Home | History | Annotate | Line # | Download | only in netatalk
at_proto.c revision 1.6.8.3
      1  1.6.8.3      yamt /*	$NetBSD: at_proto.c,v 1.6.8.3 2007/09/03 14:42:31 yamt 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.6.8.3      yamt __KERNEL_RCSID(0, "$NetBSD: at_proto.c,v 1.6.8.3 2007/09/03 14:42:31 yamt 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/radix.h>
     41      1.1  christos #include <net/if_ether.h>
     42      1.1  christos #include <netinet/in.h>
     43      1.1  christos #include <net/route.h>
     44      1.1  christos 
     45      1.1  christos #include <netatalk/at.h>
     46      1.1  christos #include <netatalk/ddp.h>
     47      1.1  christos #include <netatalk/at_var.h>
     48      1.1  christos #include <netatalk/ddp_var.h>
     49      1.1  christos #include <netatalk/at_extern.h>
     50      1.1  christos 
     51      1.6      matt DOMAIN_DEFINE(atalkdomain);	/* forward declare and add to link set */
     52      1.1  christos 
     53      1.5      matt const struct protosw atalksw[] = {
     54      1.1  christos     {
     55  1.6.8.2      yamt 	.pr_type = SOCK_DGRAM,
     56  1.6.8.2      yamt 	.pr_domain = &atalkdomain,
     57  1.6.8.2      yamt 	.pr_protocol = ATPROTO_DDP,
     58  1.6.8.2      yamt 	.pr_flags = PR_ATOMIC|PR_ADDR,
     59  1.6.8.2      yamt 	.pr_output = ddp_output,
     60  1.6.8.2      yamt 	.pr_usrreq = ddp_usrreq,
     61  1.6.8.2      yamt 	.pr_init = ddp_init,
     62      1.1  christos     },
     63      1.1  christos };
     64      1.1  christos 
     65  1.6.8.2      yamt struct domain atalkdomain = {
     66  1.6.8.1      yamt 	.dom_family = PF_APPLETALK,
     67  1.6.8.1      yamt 	.dom_name = "appletalk",
     68  1.6.8.1      yamt 	.dom_init = NULL,
     69  1.6.8.1      yamt 	.dom_externalize = NULL,
     70  1.6.8.1      yamt 	.dom_dispose = NULL,
     71  1.6.8.1      yamt 	.dom_protosw = atalksw,
     72  1.6.8.3      yamt 	.dom_protoswNPROTOSW = &atalksw[__arraycount(atalksw)],
     73  1.6.8.1      yamt 	.dom_rtattach = rn_inithead,
     74  1.6.8.1      yamt 	.dom_rtoffset = 32,
     75  1.6.8.1      yamt 	.dom_maxrtkey = sizeof(struct sockaddr_at),
     76  1.6.8.1      yamt 	.dom_ifattach = NULL,
     77  1.6.8.1      yamt 	.dom_ifdetach = NULL,
     78  1.6.8.1      yamt 	.dom_ifqueues = { &atintrq1, &atintrq2 },
     79  1.6.8.1      yamt 	.dom_link = { NULL },
     80  1.6.8.1      yamt 	.dom_mowner = MOWNER_INIT("",""),
     81  1.6.8.3      yamt 	.dom_sa_cmpofs = offsetof(struct sockaddr_at, sat_addr),
     82  1.6.8.3      yamt 	.dom_sa_cmplen = sizeof(struct at_addr),
     83  1.6.8.3      yamt 	.dom_rtcache = LIST_HEAD_INITIALIZER(atalkdomain.dom_rtcache)
     84      1.1  christos };
     85  1.6.8.3      yamt 
     86  1.6.8.3      yamt int
     87  1.6.8.3      yamt sockaddr_at_cmp(const struct sockaddr *sa1, const struct sockaddr *sa2)
     88  1.6.8.3      yamt {
     89  1.6.8.3      yamt 	int rc;
     90  1.6.8.3      yamt 	uint_fast8_t len;
     91  1.6.8.3      yamt 	const uint_fast8_t addrofs = offsetof(struct sockaddr_at, sat_addr),
     92  1.6.8.3      yamt 			   addrend = addrofs + sizeof(struct at_addr);
     93  1.6.8.3      yamt 	const struct sockaddr_at *sat1, *sat2;
     94  1.6.8.3      yamt 
     95  1.6.8.3      yamt 	sat1 = satocsat(sa1);
     96  1.6.8.3      yamt 	sat2 = satocsat(sa2);
     97  1.6.8.3      yamt 
     98  1.6.8.3      yamt 	len = MIN(addrend, MIN(sat1->sat_len, sat2->sat_len));
     99  1.6.8.3      yamt 
    100  1.6.8.3      yamt 	if (len > addrofs &&
    101  1.6.8.3      yamt 	    (rc = memcmp(&sat1->sat_addr, &sat2->sat_addr, len - addrofs)) != 0)
    102  1.6.8.3      yamt 		return rc;
    103  1.6.8.3      yamt 
    104  1.6.8.3      yamt 	return sat1->sat_len - sat2->sat_len;
    105  1.6.8.3      yamt }
    106