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