1 | /* $NetBSD: at_proto.c,v 1.21 2016/01/21 15:41:30 riastradh Exp $ */ |
2 | |
3 | /* |
4 | * Copyright (c) 1990,1991 Regents of The University of Michigan. |
5 | * All Rights Reserved. |
6 | * |
7 | * Permission to use, copy, modify, and distribute this software and |
8 | * its documentation for any purpose and without fee is hereby granted, |
9 | * provided that the above copyright notice appears in all copies and |
10 | * that both that copyright notice and this permission notice appear |
11 | * in supporting documentation, and that the name of The University |
12 | * of Michigan not be used in advertising or publicity pertaining to |
13 | * distribution of the software without specific, written prior |
14 | * permission. This software is supplied as is without expressed or |
15 | * implied warranties of any kind. |
16 | * |
17 | * This product includes software developed by the University of |
18 | * California, Berkeley and its contributors. |
19 | * |
20 | * Research Systems Unix Group |
21 | * The University of Michigan |
22 | * c/o Wesley Craig |
23 | * 535 W. William Street |
24 | * Ann Arbor, Michigan |
25 | * +1-313-764-2278 |
26 | * netatalk@umich.edu |
27 | */ |
28 | |
29 | #include <sys/cdefs.h> |
30 | __KERNEL_RCSID(0, "$NetBSD: at_proto.c,v 1.21 2016/01/21 15:41:30 riastradh Exp $" ); |
31 | |
32 | #include <sys/param.h> |
33 | #include <sys/systm.h> |
34 | #include <sys/protosw.h> |
35 | #include <sys/domain.h> |
36 | #include <sys/socket.h> |
37 | |
38 | #include <sys/kernel.h> |
39 | #include <net/if.h> |
40 | #include <net/if_ether.h> |
41 | #include <netinet/in.h> |
42 | #include <net/route.h> |
43 | |
44 | #include <netatalk/at.h> |
45 | #include <netatalk/ddp.h> |
46 | #include <netatalk/at_var.h> |
47 | #include <netatalk/ddp_var.h> |
48 | #include <netatalk/at_extern.h> |
49 | |
50 | DOMAIN_DEFINE(atalkdomain); /* forward declare and add to link set */ |
51 | |
52 | const struct protosw atalksw[] = { |
53 | { |
54 | .pr_type = SOCK_DGRAM, |
55 | .pr_domain = &atalkdomain, |
56 | .pr_protocol = ATPROTO_DDP, |
57 | .pr_flags = PR_ATOMIC|PR_ADDR, |
58 | .pr_usrreqs = &ddp_usrreqs, |
59 | .pr_init = ddp_init, |
60 | }, |
61 | }; |
62 | |
63 | struct domain atalkdomain = { |
64 | .dom_family = PF_APPLETALK, |
65 | .dom_name = "appletalk" , |
66 | .dom_init = NULL, |
67 | .dom_externalize = NULL, |
68 | .dom_dispose = NULL, |
69 | .dom_protosw = atalksw, |
70 | .dom_protoswNPROTOSW = &atalksw[__arraycount(atalksw)], |
71 | .dom_rtattach = rt_inithead, |
72 | .dom_rtoffset = 32, |
73 | .dom_maxrtkey = sizeof(struct sockaddr_at), |
74 | .dom_ifattach = NULL, |
75 | .dom_ifdetach = NULL, |
76 | .dom_ifqueues = { &atintrq1, &atintrq2 }, |
77 | .dom_link = { NULL }, |
78 | .dom_mowner = MOWNER_INIT("" ,"" ), |
79 | .dom_sa_cmpofs = offsetof(struct sockaddr_at, sat_addr), |
80 | .dom_sa_cmplen = sizeof(struct at_addr), |
81 | .dom_rtcache = LIST_HEAD_INITIALIZER(atalkdomain.dom_rtcache) |
82 | }; |
83 | |
84 | int |
85 | sockaddr_at_cmp(const struct sockaddr *sa1, const struct sockaddr *sa2) |
86 | { |
87 | int rc; |
88 | uint_fast8_t len; |
89 | const uint_fast8_t addrofs = offsetof(struct sockaddr_at, sat_addr), |
90 | addrend = addrofs + sizeof(struct at_addr); |
91 | const struct sockaddr_at *sat1, *sat2; |
92 | |
93 | sat1 = satocsat(sa1); |
94 | sat2 = satocsat(sa2); |
95 | |
96 | len = MIN(addrend, MIN(sat1->sat_len, sat2->sat_len)); |
97 | |
98 | if (len > addrofs && |
99 | (rc = memcmp(&sat1->sat_addr, &sat2->sat_addr, len - addrofs)) != 0) |
100 | return rc; |
101 | |
102 | return sat1->sat_len - sat2->sat_len; |
103 | } |
104 | |