Since I have my hands all over netatalk adding locking and restructuring

it, cinch the file's style closer to style(9) with regard to parenthesis:

  s/( /(/g
  s/ )/)/g
  s/return(/return (/g
  s/return 0/return (0)/
  s/return 1/return (1)/
This commit is contained in:
Robert Watson 2004-03-22 03:24:10 +00:00
parent 2edbecc6db
commit b8e3da4a83
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=127288
5 changed files with 576 additions and 576 deletions

View file

@ -28,8 +28,8 @@
#include <netatalk/phase2.h> #include <netatalk/phase2.h>
#include <netatalk/at_extern.h> #include <netatalk/at_extern.h>
static void aarptfree( struct aarptab *aat); static void aarptfree(struct aarptab *aat);
static void at_aarpinput( struct arpcom *ac, struct mbuf *m); static void at_aarpinput(struct arpcom *ac, struct mbuf *m);
#define AARPTAB_BSIZ 9 #define AARPTAB_BSIZ 9
#define AARPTAB_NB 19 #define AARPTAB_NB 19
@ -37,16 +37,16 @@ static void at_aarpinput( struct arpcom *ac, struct mbuf *m);
static struct aarptab aarptab[AARPTAB_SIZE]; static struct aarptab aarptab[AARPTAB_SIZE];
#define AARPTAB_HASH(a) \ #define AARPTAB_HASH(a) \
((((a).s_net << 8 ) + (a).s_node ) % AARPTAB_NB ) ((((a).s_net << 8) + (a).s_node) % AARPTAB_NB)
#define AARPTAB_LOOK(aat,addr) { \ #define AARPTAB_LOOK(aat,addr) { \
int n; \ int n; \
aat = &aarptab[ AARPTAB_HASH(addr) * AARPTAB_BSIZ ]; \ aat = &aarptab[ AARPTAB_HASH(addr) * AARPTAB_BSIZ ]; \
for ( n = 0; n < AARPTAB_BSIZ; n++, aat++ ) \ for (n = 0; n < AARPTAB_BSIZ; n++, aat++) \
if ( aat->aat_ataddr.s_net == (addr).s_net && \ if (aat->aat_ataddr.s_net == (addr).s_net && \
aat->aat_ataddr.s_node == (addr).s_node ) \ aat->aat_ataddr.s_node == (addr).s_node) \
break; \ break; \
if ( n >= AARPTAB_BSIZ ) \ if (n >= AARPTAB_BSIZ) \
aat = 0; \ aat = 0; \
} }
@ -54,7 +54,7 @@ static struct aarptab aarptab[AARPTAB_SIZE];
#define AARPT_KILLC 20 #define AARPT_KILLC 20
#define AARPT_KILLI 3 #define AARPT_KILLI 3
# if !defined( __FreeBSD__ ) # if !defined(__FreeBSD__)
extern u_char etherbroadcastaddr[6]; extern u_char etherbroadcastaddr[6];
# endif /* __FreeBSD__ */ # endif /* __FreeBSD__ */
@ -81,17 +81,17 @@ aarptimer(void *ignored)
struct aarptab *aat; struct aarptab *aat;
int i, s; int i, s;
aarptimer_ch = timeout( aarptimer, (caddr_t)0, AARPT_AGE * hz ); aarptimer_ch = timeout(aarptimer, (caddr_t)0, AARPT_AGE * hz);
aat = aarptab; aat = aarptab;
for ( i = 0; i < AARPTAB_SIZE; i++, aat++ ) { for (i = 0; i < AARPTAB_SIZE; i++, aat++) {
if ( aat->aat_flags == 0 || ( aat->aat_flags & ATF_PERM )) if (aat->aat_flags == 0 || (aat->aat_flags & ATF_PERM))
continue; continue;
if ( ++aat->aat_timer < (( aat->aat_flags & ATF_COM ) ? if (++aat->aat_timer < ((aat->aat_flags & ATF_COM) ?
AARPT_KILLC : AARPT_KILLI )) AARPT_KILLC : AARPT_KILLI))
continue; continue;
s = splimp(); s = splimp();
aarptfree( aat ); aarptfree(aat);
splx( s ); splx(s);
} }
} }
@ -101,27 +101,27 @@ aarptimer(void *ignored)
* consideration. * consideration.
*/ */
struct at_ifaddr * struct at_ifaddr *
at_ifawithnet(struct sockaddr_at *sat ) at_ifawithnet(struct sockaddr_at *sat)
{ {
struct at_ifaddr *aa; struct at_ifaddr *aa;
struct sockaddr_at *sat2; struct sockaddr_at *sat2;
for ( aa = at_ifaddr; aa; aa = aa->aa_next ) { for (aa = at_ifaddr; aa; aa = aa->aa_next) {
sat2 = &(aa->aa_addr); sat2 = &(aa->aa_addr);
if ( sat2->sat_addr.s_net == sat->sat_addr.s_net ) { if (sat2->sat_addr.s_net == sat->sat_addr.s_net) {
break; break;
} }
if( (aa->aa_flags & AFA_PHASE2 ) if((aa->aa_flags & AFA_PHASE2)
&& (ntohs(aa->aa_firstnet) <= ntohs(sat->sat_addr.s_net)) && (ntohs(aa->aa_firstnet) <= ntohs(sat->sat_addr.s_net))
&& (ntohs(aa->aa_lastnet) >= ntohs(sat->sat_addr.s_net))) { && (ntohs(aa->aa_lastnet) >= ntohs(sat->sat_addr.s_net))) {
break; break;
} }
} }
return( aa ); return (aa);
} }
static void static void
aarpwhohas( struct arpcom *ac, struct sockaddr_at *sat ) aarpwhohas(struct arpcom *ac, struct sockaddr_at *sat)
{ {
struct mbuf *m; struct mbuf *m;
struct ether_header *eh; struct ether_header *eh;
@ -130,26 +130,26 @@ aarpwhohas( struct arpcom *ac, struct sockaddr_at *sat )
struct llc *llc; struct llc *llc;
struct sockaddr sa; struct sockaddr sa;
if (( m = m_gethdr( M_DONTWAIT, MT_DATA )) == NULL ) { if ((m = m_gethdr(M_DONTWAIT, MT_DATA)) == NULL) {
return; return;
} }
#ifdef MAC #ifdef MAC
mac_create_mbuf_linklayer(&ac->ac_if, m); mac_create_mbuf_linklayer(&ac->ac_if, m);
#endif #endif
m->m_len = sizeof( *ea ); m->m_len = sizeof(*ea);
m->m_pkthdr.len = sizeof( *ea ); m->m_pkthdr.len = sizeof(*ea);
MH_ALIGN( m, sizeof( *ea )); MH_ALIGN(m, sizeof(*ea));
ea = mtod( m, struct ether_aarp *); ea = mtod(m, struct ether_aarp *);
bzero((caddr_t)ea, sizeof( *ea )); bzero((caddr_t)ea, sizeof(*ea));
ea->aarp_hrd = htons( AARPHRD_ETHER ); ea->aarp_hrd = htons(AARPHRD_ETHER);
ea->aarp_pro = htons( ETHERTYPE_AT ); ea->aarp_pro = htons(ETHERTYPE_AT);
ea->aarp_hln = sizeof( ea->aarp_sha ); ea->aarp_hln = sizeof(ea->aarp_sha);
ea->aarp_pln = sizeof( ea->aarp_spu ); ea->aarp_pln = sizeof(ea->aarp_spu);
ea->aarp_op = htons( AARPOP_REQUEST ); ea->aarp_op = htons(AARPOP_REQUEST);
bcopy((caddr_t)ac->ac_enaddr, (caddr_t)ea->aarp_sha, bcopy((caddr_t)ac->ac_enaddr, (caddr_t)ea->aarp_sha,
sizeof( ea->aarp_sha )); sizeof(ea->aarp_sha));
/* /*
* We need to check whether the output ethernet type should * We need to check whether the output ethernet type should
@ -158,55 +158,55 @@ aarpwhohas( struct arpcom *ac, struct sockaddr_at *sat )
* interface with the same address as we're looking for. If the * interface with the same address as we're looking for. If the
* net is phase 2, generate an 802.2 and SNAP header. * net is phase 2, generate an 802.2 and SNAP header.
*/ */
if ((aa = at_ifawithnet( sat )) == NULL) { if ((aa = at_ifawithnet(sat)) == NULL) {
m_freem( m ); m_freem(m);
return; return;
} }
eh = (struct ether_header *)sa.sa_data; eh = (struct ether_header *)sa.sa_data;
if ( aa->aa_flags & AFA_PHASE2 ) { if (aa->aa_flags & AFA_PHASE2) {
bcopy(atmulticastaddr, eh->ether_dhost, sizeof( eh->ether_dhost )); bcopy(atmulticastaddr, eh->ether_dhost, sizeof(eh->ether_dhost));
eh->ether_type = htons(sizeof(struct llc) + sizeof(struct ether_aarp)); eh->ether_type = htons(sizeof(struct llc) + sizeof(struct ether_aarp));
M_PREPEND( m, sizeof( struct llc ), M_TRYWAIT ); M_PREPEND(m, sizeof(struct llc), M_TRYWAIT);
if ( m == NULL ) { if (m == NULL) {
return; return;
} }
llc = mtod( m, struct llc *); llc = mtod(m, struct llc *);
llc->llc_dsap = llc->llc_ssap = LLC_SNAP_LSAP; llc->llc_dsap = llc->llc_ssap = LLC_SNAP_LSAP;
llc->llc_control = LLC_UI; llc->llc_control = LLC_UI;
bcopy(aarp_org_code, llc->llc_org_code, sizeof(aarp_org_code)); bcopy(aarp_org_code, llc->llc_org_code, sizeof(aarp_org_code));
llc->llc_ether_type = htons( ETHERTYPE_AARP ); llc->llc_ether_type = htons(ETHERTYPE_AARP);
bcopy( &AA_SAT( aa )->sat_addr.s_net, ea->aarp_spnet, bcopy(&AA_SAT(aa)->sat_addr.s_net, ea->aarp_spnet,
sizeof( ea->aarp_spnet )); sizeof(ea->aarp_spnet));
bcopy( &sat->sat_addr.s_net, ea->aarp_tpnet, bcopy(&sat->sat_addr.s_net, ea->aarp_tpnet,
sizeof( ea->aarp_tpnet )); sizeof(ea->aarp_tpnet));
ea->aarp_spnode = AA_SAT( aa )->sat_addr.s_node; ea->aarp_spnode = AA_SAT(aa)->sat_addr.s_node;
ea->aarp_tpnode = sat->sat_addr.s_node; ea->aarp_tpnode = sat->sat_addr.s_node;
} else { } else {
bcopy(ac->ac_if.if_broadcastaddr, (caddr_t)eh->ether_dhost, bcopy(ac->ac_if.if_broadcastaddr, (caddr_t)eh->ether_dhost,
sizeof( eh->ether_dhost )); sizeof(eh->ether_dhost));
eh->ether_type = htons( ETHERTYPE_AARP ); eh->ether_type = htons(ETHERTYPE_AARP);
ea->aarp_spa = AA_SAT( aa )->sat_addr.s_node; ea->aarp_spa = AA_SAT(aa)->sat_addr.s_node;
ea->aarp_tpa = sat->sat_addr.s_node; ea->aarp_tpa = sat->sat_addr.s_node;
} }
#ifdef NETATALKDEBUG #ifdef NETATALKDEBUG
printf("aarp: sending request for %u.%u\n", printf("aarp: sending request for %u.%u\n",
ntohs(AA_SAT( aa )->sat_addr.s_net), ntohs(AA_SAT(aa)->sat_addr.s_net),
AA_SAT( aa )->sat_addr.s_node); AA_SAT(aa)->sat_addr.s_node);
#endif /* NETATALKDEBUG */ #endif /* NETATALKDEBUG */
sa.sa_len = sizeof( struct sockaddr ); sa.sa_len = sizeof(struct sockaddr);
sa.sa_family = AF_UNSPEC; sa.sa_family = AF_UNSPEC;
(*ac->ac_if.if_output)(&ac->ac_if, (*ac->ac_if.if_output)(&ac->ac_if,
m, &sa, NULL); /* XXX NULL should be routing information */ m, &sa, NULL); /* XXX NULL should be routing information */
} }
int int
aarpresolve( ac, m, destsat, desten ) aarpresolve(ac, m, destsat, desten)
struct arpcom *ac; struct arpcom *ac;
struct mbuf *m; struct mbuf *m;
struct sockaddr_at *destsat; struct sockaddr_at *destsat;
@ -216,79 +216,79 @@ aarpresolve( ac, m, destsat, desten )
struct aarptab *aat; struct aarptab *aat;
int s; int s;
if ( at_broadcast( destsat )) { if (at_broadcast(destsat)) {
m->m_flags |= M_BCAST; m->m_flags |= M_BCAST;
if ((aa = at_ifawithnet( destsat )) == NULL) { if ((aa = at_ifawithnet(destsat)) == NULL) {
m_freem( m ); m_freem(m);
return( 0 ); return (0);
} }
if ( aa->aa_flags & AFA_PHASE2 ) { if (aa->aa_flags & AFA_PHASE2) {
bcopy(atmulticastaddr, (caddr_t)desten, sizeof(atmulticastaddr)); bcopy(atmulticastaddr, (caddr_t)desten, sizeof(atmulticastaddr));
} else { } else {
bcopy( ac->ac_if.if_broadcastaddr, (caddr_t)desten, bcopy(ac->ac_if.if_broadcastaddr, (caddr_t)desten,
sizeof( ac->ac_if.if_addrlen )); sizeof(ac->ac_if.if_addrlen));
} }
return( 1 ); return (1);
} }
s = splimp(); s = splimp();
AARPTAB_LOOK( aat, destsat->sat_addr ); AARPTAB_LOOK(aat, destsat->sat_addr);
if ( aat == 0 ) { /* No entry */ if (aat == 0) { /* No entry */
aat = aarptnew( &destsat->sat_addr ); aat = aarptnew(&destsat->sat_addr);
if ( aat == 0 ) { if (aat == 0) {
panic( "aarpresolve: no free entry" ); panic("aarpresolve: no free entry");
} }
aat->aat_hold = m; aat->aat_hold = m;
aarpwhohas( ac, destsat ); aarpwhohas(ac, destsat);
splx( s ); splx(s);
return( 0 ); return (0);
} }
/* found an entry */ /* found an entry */
aat->aat_timer = 0; aat->aat_timer = 0;
if ( aat->aat_flags & ATF_COM ) { /* entry is COMplete */ if (aat->aat_flags & ATF_COM) { /* entry is COMplete */
bcopy( (caddr_t)aat->aat_enaddr, (caddr_t)desten, bcopy((caddr_t)aat->aat_enaddr, (caddr_t)desten,
sizeof( aat->aat_enaddr )); sizeof(aat->aat_enaddr));
splx( s ); splx(s);
return( 1 ); return (1);
} }
/* entry has not completed */ /* entry has not completed */
if ( aat->aat_hold ) { if (aat->aat_hold) {
m_freem( aat->aat_hold ); m_freem(aat->aat_hold);
} }
aat->aat_hold = m; aat->aat_hold = m;
aarpwhohas( ac, destsat ); aarpwhohas(ac, destsat);
splx( s ); splx(s);
return( 0 ); return (0);
} }
void void
aarpintr( m ) aarpintr(m)
struct mbuf *m; struct mbuf *m;
{ {
struct arphdr *ar; struct arphdr *ar;
struct arpcom *ac; struct arpcom *ac;
ac = (struct arpcom *)m->m_pkthdr.rcvif; ac = (struct arpcom *)m->m_pkthdr.rcvif;
if ( ac->ac_if.if_flags & IFF_NOARP ) if (ac->ac_if.if_flags & IFF_NOARP)
goto out; goto out;
if ( m->m_len < sizeof( struct arphdr )) { if (m->m_len < sizeof(struct arphdr)) {
goto out; goto out;
} }
ar = mtod( m, struct arphdr *); ar = mtod(m, struct arphdr *);
if ( ntohs( ar->ar_hrd ) != AARPHRD_ETHER ) { if (ntohs(ar->ar_hrd) != AARPHRD_ETHER) {
goto out; goto out;
} }
if ( m->m_len < sizeof( struct arphdr ) + 2 * ar->ar_hln + if (m->m_len < sizeof(struct arphdr) + 2 * ar->ar_hln +
2 * ar->ar_pln ) { 2 * ar->ar_pln) {
goto out; goto out;
} }
switch( ntohs( ar->ar_pro )) { switch(ntohs(ar->ar_pro)) {
case ETHERTYPE_AT : case ETHERTYPE_AT :
at_aarpinput( ac, m ); at_aarpinput(ac, m);
return; return;
default: default:
@ -296,11 +296,11 @@ aarpintr( m )
} }
out: out:
m_freem( m ); m_freem(m);
} }
static void static void
at_aarpinput( struct arpcom *ac, struct mbuf *m) at_aarpinput(struct arpcom *ac, struct mbuf *m)
{ {
struct ether_aarp *ea; struct ether_aarp *ea;
struct at_ifaddr *aa; struct at_ifaddr *aa;
@ -315,28 +315,28 @@ at_aarpinput( struct arpcom *ac, struct mbuf *m)
GIANT_REQUIRED; GIANT_REQUIRED;
ea = mtod( m, struct ether_aarp *); ea = mtod(m, struct ether_aarp *);
/* Check to see if from my hardware address */ /* Check to see if from my hardware address */
if ( !bcmp(( caddr_t )ea->aarp_sha, ( caddr_t )ac->ac_enaddr, if (!bcmp((caddr_t)ea->aarp_sha, (caddr_t)ac->ac_enaddr,
sizeof( ac->ac_enaddr ))) { sizeof(ac->ac_enaddr))) {
m_freem( m ); m_freem(m);
return; return;
} }
op = ntohs( ea->aarp_op ); op = ntohs(ea->aarp_op);
bcopy( ea->aarp_tpnet, &net, sizeof( net )); bcopy(ea->aarp_tpnet, &net, sizeof(net));
if ( net != 0 ) { /* should be ATADDR_ANYNET? */ if (net != 0) { /* should be ATADDR_ANYNET? */
sat.sat_len = sizeof(struct sockaddr_at); sat.sat_len = sizeof(struct sockaddr_at);
sat.sat_family = AF_APPLETALK; sat.sat_family = AF_APPLETALK;
sat.sat_addr.s_net = net; sat.sat_addr.s_net = net;
if ((aa = at_ifawithnet( &sat )) == NULL) { if ((aa = at_ifawithnet(&sat)) == NULL) {
m_freem( m ); m_freem(m);
return; return;
} }
bcopy( ea->aarp_spnet, &spa.s_net, sizeof( spa.s_net )); bcopy(ea->aarp_spnet, &spa.s_net, sizeof(spa.s_net));
bcopy( ea->aarp_tpnet, &tpa.s_net, sizeof( tpa.s_net )); bcopy(ea->aarp_tpnet, &tpa.s_net, sizeof(tpa.s_net));
} else { } else {
/* /*
* Since we don't know the net, we just look for the first * Since we don't know the net, we just look for the first
@ -344,141 +344,141 @@ at_aarpinput( struct arpcom *ac, struct mbuf *m)
*/ */
for (aa = (struct at_ifaddr *)TAILQ_FIRST(&ac->ac_if.if_addrhead); aa; for (aa = (struct at_ifaddr *)TAILQ_FIRST(&ac->ac_if.if_addrhead); aa;
aa = (struct at_ifaddr *)aa->aa_ifa.ifa_link.tqe_next) { aa = (struct at_ifaddr *)aa->aa_ifa.ifa_link.tqe_next) {
if ( AA_SAT( aa )->sat_family == AF_APPLETALK && if (AA_SAT(aa)->sat_family == AF_APPLETALK &&
( aa->aa_flags & AFA_PHASE2 ) == 0 ) { (aa->aa_flags & AFA_PHASE2) == 0) {
break; break;
} }
} }
if ( aa == NULL ) { if (aa == NULL) {
m_freem( m ); m_freem(m);
return; return;
} }
tpa.s_net = spa.s_net = AA_SAT( aa )->sat_addr.s_net; tpa.s_net = spa.s_net = AA_SAT(aa)->sat_addr.s_net;
} }
spa.s_node = ea->aarp_spnode; spa.s_node = ea->aarp_spnode;
tpa.s_node = ea->aarp_tpnode; tpa.s_node = ea->aarp_tpnode;
ma.s_net = AA_SAT( aa )->sat_addr.s_net; ma.s_net = AA_SAT(aa)->sat_addr.s_net;
ma.s_node = AA_SAT( aa )->sat_addr.s_node; ma.s_node = AA_SAT(aa)->sat_addr.s_node;
/* /*
* This looks like it's from us. * This looks like it's from us.
*/ */
if ( spa.s_net == ma.s_net && spa.s_node == ma.s_node ) { if (spa.s_net == ma.s_net && spa.s_node == ma.s_node) {
if ( aa->aa_flags & AFA_PROBING ) { if (aa->aa_flags & AFA_PROBING) {
/* /*
* We're probing, someone either responded to our probe, or * We're probing, someone either responded to our probe, or
* probed for the same address we'd like to use. Change the * probed for the same address we'd like to use. Change the
* address we're probing for. * address we're probing for.
*/ */
untimeout( aarpprobe, ac, aa->aa_ch ); untimeout(aarpprobe, ac, aa->aa_ch);
wakeup( aa ); wakeup(aa);
m_freem( m ); m_freem(m);
return; return;
} else if ( op != AARPOP_PROBE ) { } else if (op != AARPOP_PROBE) {
/* /*
* This is not a probe, and we're not probing. This means * This is not a probe, and we're not probing. This means
* that someone's saying they have the same source address * that someone's saying they have the same source address
* as the one we're using. Get upset... * as the one we're using. Get upset...
*/ */
log( LOG_ERR, log(LOG_ERR,
"aarp: duplicate AT address!! %x:%x:%x:%x:%x:%x\n", "aarp: duplicate AT address!! %x:%x:%x:%x:%x:%x\n",
ea->aarp_sha[ 0 ], ea->aarp_sha[ 1 ], ea->aarp_sha[ 2 ], ea->aarp_sha[ 0 ], ea->aarp_sha[ 1 ], ea->aarp_sha[ 2 ],
ea->aarp_sha[ 3 ], ea->aarp_sha[ 4 ], ea->aarp_sha[ 5 ]); ea->aarp_sha[ 3 ], ea->aarp_sha[ 4 ], ea->aarp_sha[ 5 ]);
m_freem( m ); m_freem(m);
return; return;
} }
} }
AARPTAB_LOOK( aat, spa ); AARPTAB_LOOK(aat, spa);
if ( aat ) { if (aat) {
if ( op == AARPOP_PROBE ) { if (op == AARPOP_PROBE) {
/* /*
* Someone's probing for spa, dealocate the one we've got, * Someone's probing for spa, dealocate the one we've got,
* so that if the prober keeps the address, we'll be able * so that if the prober keeps the address, we'll be able
* to arp for him. * to arp for him.
*/ */
aarptfree( aat ); aarptfree(aat);
m_freem( m ); m_freem(m);
return; return;
} }
bcopy(( caddr_t )ea->aarp_sha, ( caddr_t )aat->aat_enaddr, bcopy((caddr_t)ea->aarp_sha, (caddr_t)aat->aat_enaddr,
sizeof( ea->aarp_sha )); sizeof(ea->aarp_sha));
aat->aat_flags |= ATF_COM; aat->aat_flags |= ATF_COM;
if ( aat->aat_hold ) { if (aat->aat_hold) {
struct mbuf *mhold = aat->aat_hold; struct mbuf *mhold = aat->aat_hold;
aat->aat_hold = NULL; aat->aat_hold = NULL;
sat.sat_len = sizeof(struct sockaddr_at); sat.sat_len = sizeof(struct sockaddr_at);
sat.sat_family = AF_APPLETALK; sat.sat_family = AF_APPLETALK;
sat.sat_addr = spa; sat.sat_addr = spa;
(*ac->ac_if.if_output)( &ac->ac_if, mhold, (*ac->ac_if.if_output)(&ac->ac_if, mhold,
(struct sockaddr *)&sat, NULL); /* XXX */ (struct sockaddr *)&sat, NULL); /* XXX */
} }
} else if ((tpa.s_net == ma.s_net) } else if ((tpa.s_net == ma.s_net)
&& (tpa.s_node == ma.s_node) && (tpa.s_node == ma.s_node)
&& (op != AARPOP_PROBE) && (op != AARPOP_PROBE)
&& ((aat = aarptnew( &spa )) != NULL)) { && ((aat = aarptnew(&spa)) != NULL)) {
bcopy(( caddr_t )ea->aarp_sha, ( caddr_t )aat->aat_enaddr, bcopy((caddr_t)ea->aarp_sha, (caddr_t)aat->aat_enaddr,
sizeof( ea->aarp_sha )); sizeof(ea->aarp_sha));
aat->aat_flags |= ATF_COM; aat->aat_flags |= ATF_COM;
} }
/* /*
* Don't respond to responses, and never respond if we're * Don't respond to responses, and never respond if we're
* still probing. * still probing.
*/ */
if ( tpa.s_net != ma.s_net || tpa.s_node != ma.s_node || if (tpa.s_net != ma.s_net || tpa.s_node != ma.s_node ||
op == AARPOP_RESPONSE || ( aa->aa_flags & AFA_PROBING )) { op == AARPOP_RESPONSE || (aa->aa_flags & AFA_PROBING)) {
m_freem( m ); m_freem(m);
return; return;
} }
bcopy(( caddr_t )ea->aarp_sha, ( caddr_t )ea->aarp_tha, bcopy((caddr_t)ea->aarp_sha, (caddr_t)ea->aarp_tha,
sizeof( ea->aarp_sha )); sizeof(ea->aarp_sha));
bcopy(( caddr_t )ac->ac_enaddr, ( caddr_t )ea->aarp_sha, bcopy((caddr_t)ac->ac_enaddr, (caddr_t)ea->aarp_sha,
sizeof( ea->aarp_sha )); sizeof(ea->aarp_sha));
/* XXX */ /* XXX */
eh = (struct ether_header *)sa.sa_data; eh = (struct ether_header *)sa.sa_data;
bcopy(( caddr_t )ea->aarp_tha, ( caddr_t )eh->ether_dhost, bcopy((caddr_t)ea->aarp_tha, (caddr_t)eh->ether_dhost,
sizeof( eh->ether_dhost )); sizeof(eh->ether_dhost));
if ( aa->aa_flags & AFA_PHASE2 ) { if (aa->aa_flags & AFA_PHASE2) {
eh->ether_type = htons( sizeof( struct llc ) + eh->ether_type = htons(sizeof(struct llc) +
sizeof( struct ether_aarp )); sizeof(struct ether_aarp));
M_PREPEND( m, sizeof( struct llc ), M_DONTWAIT ); M_PREPEND(m, sizeof(struct llc), M_DONTWAIT);
if ( m == NULL ) { if (m == NULL) {
return; return;
} }
llc = mtod( m, struct llc *); llc = mtod(m, struct llc *);
llc->llc_dsap = llc->llc_ssap = LLC_SNAP_LSAP; llc->llc_dsap = llc->llc_ssap = LLC_SNAP_LSAP;
llc->llc_control = LLC_UI; llc->llc_control = LLC_UI;
bcopy( aarp_org_code, llc->llc_org_code, sizeof( aarp_org_code )); bcopy(aarp_org_code, llc->llc_org_code, sizeof(aarp_org_code));
llc->llc_ether_type = htons( ETHERTYPE_AARP ); llc->llc_ether_type = htons(ETHERTYPE_AARP);
bcopy( ea->aarp_spnet, ea->aarp_tpnet, sizeof( ea->aarp_tpnet )); bcopy(ea->aarp_spnet, ea->aarp_tpnet, sizeof(ea->aarp_tpnet));
bcopy( &ma.s_net, ea->aarp_spnet, sizeof( ea->aarp_spnet )); bcopy(&ma.s_net, ea->aarp_spnet, sizeof(ea->aarp_spnet));
} else { } else {
eh->ether_type = htons( ETHERTYPE_AARP ); eh->ether_type = htons(ETHERTYPE_AARP);
} }
ea->aarp_tpnode = ea->aarp_spnode; ea->aarp_tpnode = ea->aarp_spnode;
ea->aarp_spnode = ma.s_node; ea->aarp_spnode = ma.s_node;
ea->aarp_op = htons( AARPOP_RESPONSE ); ea->aarp_op = htons(AARPOP_RESPONSE);
sa.sa_len = sizeof( struct sockaddr ); sa.sa_len = sizeof(struct sockaddr);
sa.sa_family = AF_UNSPEC; sa.sa_family = AF_UNSPEC;
(*ac->ac_if.if_output)( &ac->ac_if, m, &sa, NULL); /* XXX */ (*ac->ac_if.if_output)(&ac->ac_if, m, &sa, NULL); /* XXX */
return; return;
} }
static void static void
aarptfree( struct aarptab *aat) aarptfree(struct aarptab *aat)
{ {
if ( aat->aat_hold ) if (aat->aat_hold)
m_freem( aat->aat_hold ); m_freem(aat->aat_hold);
aat->aat_hold = NULL; aat->aat_hold = NULL;
aat->aat_timer = aat->aat_flags = 0; aat->aat_timer = aat->aat_flags = 0;
aat->aat_ataddr.s_net = 0; aat->aat_ataddr.s_net = 0;
@ -486,7 +486,7 @@ aarptfree( struct aarptab *aat)
} }
struct aarptab * struct aarptab *
aarptnew( addr ) aarptnew(addr)
struct at_addr *addr; struct at_addr *addr;
{ {
int n; int n;
@ -494,34 +494,34 @@ aarptnew( addr )
struct aarptab *aat, *aato = NULL; struct aarptab *aat, *aato = NULL;
static int first = 1; static int first = 1;
if ( first ) { if (first) {
first = 0; first = 0;
aarptimer_ch = timeout( aarptimer, (caddr_t)0, hz ); aarptimer_ch = timeout(aarptimer, (caddr_t)0, hz);
} }
aat = &aarptab[ AARPTAB_HASH( *addr ) * AARPTAB_BSIZ ]; aat = &aarptab[ AARPTAB_HASH(*addr) * AARPTAB_BSIZ ];
for ( n = 0; n < AARPTAB_BSIZ; n++, aat++ ) { for (n = 0; n < AARPTAB_BSIZ; n++, aat++) {
if ( aat->aat_flags == 0 ) if (aat->aat_flags == 0)
goto out; goto out;
if ( aat->aat_flags & ATF_PERM ) if (aat->aat_flags & ATF_PERM)
continue; continue;
if ((int) aat->aat_timer > oldest ) { if ((int) aat->aat_timer > oldest) {
oldest = aat->aat_timer; oldest = aat->aat_timer;
aato = aat; aato = aat;
} }
} }
if ( aato == NULL ) if (aato == NULL)
return( NULL ); return (NULL);
aat = aato; aat = aato;
aarptfree( aat ); aarptfree(aat);
out: out:
aat->aat_ataddr = *addr; aat->aat_ataddr = *addr;
aat->aat_flags = ATF_INUSE; aat->aat_flags = ATF_INUSE;
return( aat ); return (aat);
} }
void void
aarpprobe( void *arg ) aarpprobe(void *arg)
{ {
struct arpcom *ac = arg; struct arpcom *ac = arg;
struct mbuf *m; struct mbuf *m;
@ -540,80 +540,80 @@ aarpprobe( void *arg )
*/ */
for (aa = (struct at_ifaddr *)TAILQ_FIRST(&ac->ac_if.if_addrhead); aa; for (aa = (struct at_ifaddr *)TAILQ_FIRST(&ac->ac_if.if_addrhead); aa;
aa = (struct at_ifaddr *)aa->aa_ifa.ifa_link.tqe_next) { aa = (struct at_ifaddr *)aa->aa_ifa.ifa_link.tqe_next) {
if ( AA_SAT( aa )->sat_family == AF_APPLETALK && if (AA_SAT(aa)->sat_family == AF_APPLETALK &&
( aa->aa_flags & AFA_PROBING )) { (aa->aa_flags & AFA_PROBING)) {
break; break;
} }
} }
if ( aa == NULL ) { /* serious error XXX */ if (aa == NULL) { /* serious error XXX */
printf( "aarpprobe why did this happen?!\n" ); printf("aarpprobe why did this happen?!\n");
return; return;
} }
if ( aa->aa_probcnt <= 0 ) { if (aa->aa_probcnt <= 0) {
aa->aa_flags &= ~AFA_PROBING; aa->aa_flags &= ~AFA_PROBING;
wakeup( aa ); wakeup(aa);
return; return;
} else { } else {
aa->aa_ch = timeout( aarpprobe, (caddr_t)ac, hz / 5 ); aa->aa_ch = timeout(aarpprobe, (caddr_t)ac, hz / 5);
} }
if (( m = m_gethdr( M_DONTWAIT, MT_DATA )) == NULL ) { if ((m = m_gethdr(M_DONTWAIT, MT_DATA)) == NULL) {
return; return;
} }
#ifdef MAC #ifdef MAC
mac_create_mbuf_linklayer(&ac->ac_if, m); mac_create_mbuf_linklayer(&ac->ac_if, m);
#endif #endif
m->m_len = sizeof( *ea ); m->m_len = sizeof(*ea);
m->m_pkthdr.len = sizeof( *ea ); m->m_pkthdr.len = sizeof(*ea);
MH_ALIGN( m, sizeof( *ea )); MH_ALIGN(m, sizeof(*ea));
ea = mtod( m, struct ether_aarp *); ea = mtod(m, struct ether_aarp *);
bzero((caddr_t)ea, sizeof( *ea )); bzero((caddr_t)ea, sizeof(*ea));
ea->aarp_hrd = htons( AARPHRD_ETHER ); ea->aarp_hrd = htons(AARPHRD_ETHER);
ea->aarp_pro = htons( ETHERTYPE_AT ); ea->aarp_pro = htons(ETHERTYPE_AT);
ea->aarp_hln = sizeof( ea->aarp_sha ); ea->aarp_hln = sizeof(ea->aarp_sha);
ea->aarp_pln = sizeof( ea->aarp_spu ); ea->aarp_pln = sizeof(ea->aarp_spu);
ea->aarp_op = htons( AARPOP_PROBE ); ea->aarp_op = htons(AARPOP_PROBE);
bcopy((caddr_t)ac->ac_enaddr, (caddr_t)ea->aarp_sha, bcopy((caddr_t)ac->ac_enaddr, (caddr_t)ea->aarp_sha,
sizeof( ea->aarp_sha )); sizeof(ea->aarp_sha));
eh = (struct ether_header *)sa.sa_data; eh = (struct ether_header *)sa.sa_data;
if ( aa->aa_flags & AFA_PHASE2 ) { if (aa->aa_flags & AFA_PHASE2) {
bcopy(atmulticastaddr, eh->ether_dhost, sizeof( eh->ether_dhost )); bcopy(atmulticastaddr, eh->ether_dhost, sizeof(eh->ether_dhost));
eh->ether_type = htons( sizeof( struct llc ) + eh->ether_type = htons(sizeof(struct llc) +
sizeof( struct ether_aarp )); sizeof(struct ether_aarp));
M_PREPEND( m, sizeof( struct llc ), M_TRYWAIT ); M_PREPEND(m, sizeof(struct llc), M_TRYWAIT);
if ( m == NULL ) { if (m == NULL) {
return; return;
} }
llc = mtod( m, struct llc *); llc = mtod(m, struct llc *);
llc->llc_dsap = llc->llc_ssap = LLC_SNAP_LSAP; llc->llc_dsap = llc->llc_ssap = LLC_SNAP_LSAP;
llc->llc_control = LLC_UI; llc->llc_control = LLC_UI;
bcopy( aarp_org_code, llc->llc_org_code, sizeof( aarp_org_code )); bcopy(aarp_org_code, llc->llc_org_code, sizeof(aarp_org_code));
llc->llc_ether_type = htons( ETHERTYPE_AARP ); llc->llc_ether_type = htons(ETHERTYPE_AARP);
bcopy( &AA_SAT( aa )->sat_addr.s_net, ea->aarp_spnet, bcopy(&AA_SAT(aa)->sat_addr.s_net, ea->aarp_spnet,
sizeof( ea->aarp_spnet )); sizeof(ea->aarp_spnet));
bcopy( &AA_SAT( aa )->sat_addr.s_net, ea->aarp_tpnet, bcopy(&AA_SAT(aa)->sat_addr.s_net, ea->aarp_tpnet,
sizeof( ea->aarp_tpnet )); sizeof(ea->aarp_tpnet));
ea->aarp_spnode = ea->aarp_tpnode = AA_SAT( aa )->sat_addr.s_node; ea->aarp_spnode = ea->aarp_tpnode = AA_SAT(aa)->sat_addr.s_node;
} else { } else {
bcopy(ac->ac_if.if_broadcastaddr, (caddr_t)eh->ether_dhost, bcopy(ac->ac_if.if_broadcastaddr, (caddr_t)eh->ether_dhost,
sizeof( eh->ether_dhost )); sizeof(eh->ether_dhost));
eh->ether_type = htons( ETHERTYPE_AARP ); eh->ether_type = htons(ETHERTYPE_AARP);
ea->aarp_spa = ea->aarp_tpa = AA_SAT( aa )->sat_addr.s_node; ea->aarp_spa = ea->aarp_tpa = AA_SAT(aa)->sat_addr.s_node;
} }
#ifdef NETATALKDEBUG #ifdef NETATALKDEBUG
printf("aarp: sending probe for %u.%u\n", printf("aarp: sending probe for %u.%u\n",
ntohs(AA_SAT( aa )->sat_addr.s_net), ntohs(AA_SAT(aa)->sat_addr.s_net),
AA_SAT( aa )->sat_addr.s_node); AA_SAT(aa)->sat_addr.s_node);
#endif /* NETATALKDEBUG */ #endif /* NETATALKDEBUG */
sa.sa_len = sizeof( struct sockaddr ); sa.sa_len = sizeof(struct sockaddr);
sa.sa_family = AF_UNSPEC; sa.sa_family = AF_UNSPEC;
(*ac->ac_if.if_output)(&ac->ac_if, m, &sa, NULL); /* XXX */ (*ac->ac_if.if_output)(&ac->ac_if, m, &sa, NULL); /* XXX */
aa->aa_probcnt--; aa->aa_probcnt--;
@ -625,10 +625,10 @@ aarp_clean(void)
struct aarptab *aat; struct aarptab *aat;
int i; int i;
untimeout( aarptimer, 0, aarptimer_ch ); untimeout(aarptimer, 0, aarptimer_ch);
for ( i = 0, aat = aarptab; i < AARPTAB_SIZE; i++, aat++ ) { for (i = 0, aat = aarptab; i < AARPTAB_SIZE; i++, aat++) {
if ( aat->aat_hold ) { if (aat->aat_hold) {
m_freem( aat->aat_hold ); m_freem(aat->aat_hold);
aat->aat_hold = NULL; aat->aat_hold = NULL;
} }
} }

View file

@ -31,19 +31,19 @@ static int aa_delsingleroute(struct ifaddr *ifa,
struct at_addr *addr, struct at_addr *mask); struct at_addr *addr, struct at_addr *mask);
static int aa_dosingleroute(struct ifaddr *ifa, struct at_addr *addr, static int aa_dosingleroute(struct ifaddr *ifa, struct at_addr *addr,
struct at_addr *mask, int cmd, int flags); struct at_addr *mask, int cmd, int flags);
static int at_scrub( struct ifnet *ifp, struct at_ifaddr *aa ); static int at_scrub(struct ifnet *ifp, struct at_ifaddr *aa);
static int at_ifinit( struct ifnet *ifp, struct at_ifaddr *aa, static int at_ifinit(struct ifnet *ifp, struct at_ifaddr *aa,
struct sockaddr_at *sat ); struct sockaddr_at *sat);
static int aa_claim_addr(struct ifaddr *ifa, struct sockaddr *gw); static int aa_claim_addr(struct ifaddr *ifa, struct sockaddr *gw);
# define sateqaddr(a,b) ((a)->sat_len == (b)->sat_len && \ # define sateqaddr(a,b) ((a)->sat_len == (b)->sat_len && \
(a)->sat_family == (b)->sat_family && \ (a)->sat_family == (b)->sat_family && \
(a)->sat_addr.s_net == (b)->sat_addr.s_net && \ (a)->sat_addr.s_net == (b)->sat_addr.s_net && \
(a)->sat_addr.s_node == (b)->sat_addr.s_node ) (a)->sat_addr.s_node == (b)->sat_addr.s_node)
int int
at_control(struct socket *so, u_long cmd, caddr_t data, at_control(struct socket *so, u_long cmd, caddr_t data,
struct ifnet *ifp, struct thread *td ) struct ifnet *ifp, struct thread *td)
{ {
struct ifreq *ifr = (struct ifreq *)data; struct ifreq *ifr = (struct ifreq *)data;
struct sockaddr_at *sat; struct sockaddr_at *sat;
@ -56,9 +56,9 @@ at_control(struct socket *so, u_long cmd, caddr_t data,
/* /*
* If we have an ifp, then find the matching at_ifaddr if it exists * If we have an ifp, then find the matching at_ifaddr if it exists
*/ */
if ( ifp ) { if (ifp) {
for ( aa = at_ifaddr; aa; aa = aa->aa_next ) { for (aa = at_ifaddr; aa; aa = aa->aa_next) {
if ( aa->aa_ifp == ifp ) break; if (aa->aa_ifp == ifp) break;
} }
} }
@ -68,7 +68,7 @@ at_control(struct socket *so, u_long cmd, caddr_t data,
* so that they start to look more similar to other protocols etc. * so that they start to look more similar to other protocols etc.
*/ */
switch ( cmd ) { switch (cmd) {
case SIOCAIFADDR: case SIOCAIFADDR:
case SIOCDIFADDR: case SIOCDIFADDR:
/* /*
@ -78,10 +78,10 @@ at_control(struct socket *so, u_long cmd, caddr_t data,
* This may leave aa pointing to the first address on the * This may leave aa pointing to the first address on the
* NEXT interface! * NEXT interface!
*/ */
if ( ifra->ifra_addr.sat_family == AF_APPLETALK ) { if (ifra->ifra_addr.sat_family == AF_APPLETALK) {
for ( ; aa; aa = aa->aa_next ) { for (; aa; aa = aa->aa_next) {
if ( aa->aa_ifp == ifp && if (aa->aa_ifp == ifp &&
sateqaddr( &aa->aa_addr, &ifra->ifra_addr )) { sateqaddr(&aa->aa_addr, &ifra->ifra_addr)) {
break; break;
} }
} }
@ -90,8 +90,8 @@ at_control(struct socket *so, u_long cmd, caddr_t data,
* If we a retrying to delete an addres but didn't find such, * If we a retrying to delete an addres but didn't find such,
* then rewurn with an error * then rewurn with an error
*/ */
if ( cmd == SIOCDIFADDR && aa == NULL ) { if (cmd == SIOCDIFADDR && aa == NULL) {
return( EADDRNOTAVAIL ); return (EADDRNOTAVAIL);
} }
/*FALLTHROUGH*/ /*FALLTHROUGH*/
@ -99,21 +99,21 @@ at_control(struct socket *so, u_long cmd, caddr_t data,
/* /*
* If we are not superuser, then we don't get to do these ops. * If we are not superuser, then we don't get to do these ops.
*/ */
if ( suser(td) ) { if (suser(td)) {
return( EPERM ); return (EPERM);
} }
sat = satosat( &ifr->ifr_addr ); sat = satosat(&ifr->ifr_addr);
nr = (struct netrange *)sat->sat_zero; nr = (struct netrange *)sat->sat_zero;
if ( nr->nr_phase == 1 ) { if (nr->nr_phase == 1) {
/* /*
* Look for a phase 1 address on this interface. * Look for a phase 1 address on this interface.
* This may leave aa pointing to the first address on the * This may leave aa pointing to the first address on the
* NEXT interface! * NEXT interface!
*/ */
for ( ; aa; aa = aa->aa_next ) { for (; aa; aa = aa->aa_next) {
if ( aa->aa_ifp == ifp && if (aa->aa_ifp == ifp &&
( aa->aa_flags & AFA_PHASE2 ) == 0 ) { (aa->aa_flags & AFA_PHASE2) == 0) {
break; break;
} }
} }
@ -123,23 +123,23 @@ at_control(struct socket *so, u_long cmd, caddr_t data,
* This may leave aa pointing to the first address on the * This may leave aa pointing to the first address on the
* NEXT interface! * NEXT interface!
*/ */
for ( ; aa; aa = aa->aa_next ) { for (; aa; aa = aa->aa_next) {
if ( aa->aa_ifp == ifp && ( aa->aa_flags & AFA_PHASE2 )) { if (aa->aa_ifp == ifp && (aa->aa_flags & AFA_PHASE2)) {
break; break;
} }
} }
} }
if ( ifp == NULL ) if (ifp == NULL)
panic( "at_control" ); panic("at_control");
/* /*
* If we failed to find an existing at_ifaddr entry, then we * If we failed to find an existing at_ifaddr entry, then we
* allocate a fresh one. * allocate a fresh one.
*/ */
if ( aa == NULL ) { if (aa == NULL) {
aa0 = malloc(sizeof(struct at_ifaddr), M_IFADDR, M_WAITOK | M_ZERO); aa0 = malloc(sizeof(struct at_ifaddr), M_IFADDR, M_WAITOK | M_ZERO);
if (( aa = at_ifaddr ) != NULL ) { if ((aa = at_ifaddr) != NULL) {
/* /*
* Don't let the loopback be first, since the first * Don't let the loopback be first, since the first
* address is the machine's default address for * address is the machine's default address for
@ -147,12 +147,12 @@ at_control(struct socket *so, u_long cmd, caddr_t data,
* If it is, stick ourself in front, otherwise * If it is, stick ourself in front, otherwise
* go to the back of the list. * go to the back of the list.
*/ */
if ( at_ifaddr->aa_ifp->if_flags & IFF_LOOPBACK ) { if (at_ifaddr->aa_ifp->if_flags & IFF_LOOPBACK) {
aa = aa0; aa = aa0;
aa->aa_next = at_ifaddr; aa->aa_next = at_ifaddr;
at_ifaddr = aa; at_ifaddr = aa;
} else { } else {
for ( ; aa->aa_next; aa = aa->aa_next ) for (; aa->aa_next; aa = aa->aa_next)
; ;
aa->aa_next = aa0; aa->aa_next = aa0;
} }
@ -181,7 +181,7 @@ at_control(struct socket *so, u_long cmd, caddr_t data,
/* /*
* Set/clear the phase 2 bit. * Set/clear the phase 2 bit.
*/ */
if ( nr->nr_phase == 1 ) { if (nr->nr_phase == 1) {
aa->aa_flags &= ~AFA_PHASE2; aa->aa_flags &= ~AFA_PHASE2;
} else { } else {
aa->aa_flags |= AFA_PHASE2; aa->aa_flags |= AFA_PHASE2;
@ -195,21 +195,21 @@ at_control(struct socket *so, u_long cmd, caddr_t data,
/* /*
* If we DID find one then we clobber any routes dependent on it.. * If we DID find one then we clobber any routes dependent on it..
*/ */
at_scrub( ifp, aa ); at_scrub(ifp, aa);
} }
break; break;
case SIOCGIFADDR : case SIOCGIFADDR :
sat = satosat( &ifr->ifr_addr ); sat = satosat(&ifr->ifr_addr);
nr = (struct netrange *)sat->sat_zero; nr = (struct netrange *)sat->sat_zero;
if ( nr->nr_phase == 1 ) { if (nr->nr_phase == 1) {
/* /*
* If the request is specifying phase 1, then * If the request is specifying phase 1, then
* only look at a phase one address * only look at a phase one address
*/ */
for ( ; aa; aa = aa->aa_next ) { for (; aa; aa = aa->aa_next) {
if ( aa->aa_ifp == ifp && if (aa->aa_ifp == ifp &&
( aa->aa_flags & AFA_PHASE2 ) == 0 ) { (aa->aa_flags & AFA_PHASE2) == 0) {
break; break;
} }
} }
@ -217,15 +217,15 @@ at_control(struct socket *so, u_long cmd, caddr_t data,
/* /*
* default to phase 2 * default to phase 2
*/ */
for ( ; aa; aa = aa->aa_next ) { for (; aa; aa = aa->aa_next) {
if ( aa->aa_ifp == ifp && ( aa->aa_flags & AFA_PHASE2 )) { if (aa->aa_ifp == ifp && (aa->aa_flags & AFA_PHASE2)) {
break; break;
} }
} }
} }
if ( aa == NULL ) if (aa == NULL)
return( EADDRNOTAVAIL ); return (EADDRNOTAVAIL);
break; break;
} }
@ -233,7 +233,7 @@ at_control(struct socket *so, u_long cmd, caddr_t data,
* By the time this switch is run we should be able to assume that * By the time this switch is run we should be able to assume that
* the "aa" pointer is valid when needed. * the "aa" pointer is valid when needed.
*/ */
switch ( cmd ) { switch (cmd) {
case SIOCGIFADDR: case SIOCGIFADDR:
/* /*
@ -252,19 +252,19 @@ at_control(struct socket *so, u_long cmd, caddr_t data,
break; break;
case SIOCSIFADDR: case SIOCSIFADDR:
return( at_ifinit( ifp, aa, (struct sockaddr_at *)&ifr->ifr_addr )); return (at_ifinit(ifp, aa, (struct sockaddr_at *)&ifr->ifr_addr));
case SIOCAIFADDR: case SIOCAIFADDR:
if ( sateqaddr( &ifra->ifra_addr, &aa->aa_addr )) { if (sateqaddr(&ifra->ifra_addr, &aa->aa_addr)) {
return( 0 ); return (0);
} }
return( at_ifinit( ifp, aa, (struct sockaddr_at *)&ifr->ifr_addr )); return (at_ifinit(ifp, aa, (struct sockaddr_at *)&ifr->ifr_addr));
case SIOCDIFADDR: case SIOCDIFADDR:
/* /*
* scrub all routes.. didn't we just DO this? XXX yes, del it * scrub all routes.. didn't we just DO this? XXX yes, del it
*/ */
at_scrub( ifp, aa ); at_scrub(ifp, aa);
/* /*
* remove the ifaddr from the interface * remove the ifaddr from the interface
@ -277,20 +277,20 @@ at_control(struct socket *so, u_long cmd, caddr_t data,
* as well, or we'd be in deep trouble * as well, or we'd be in deep trouble
*/ */
aa0 = aa; aa0 = aa;
if ( aa0 == ( aa = at_ifaddr )) { if (aa0 == (aa = at_ifaddr)) {
at_ifaddr = aa->aa_next; at_ifaddr = aa->aa_next;
} else { } else {
while ( aa->aa_next && ( aa->aa_next != aa0 )) { while (aa->aa_next && (aa->aa_next != aa0)) {
aa = aa->aa_next; aa = aa->aa_next;
} }
/* /*
* if we found it, remove it, otherwise we screwed up. * if we found it, remove it, otherwise we screwed up.
*/ */
if ( aa->aa_next ) { if (aa->aa_next) {
aa->aa_next = aa0->aa_next; aa->aa_next = aa0->aa_next;
} else { } else {
panic( "at_control" ); panic("at_control");
} }
} }
@ -301,11 +301,11 @@ at_control(struct socket *so, u_long cmd, caddr_t data,
break; break;
default: default:
if ( ifp == NULL || ifp->if_ioctl == NULL ) if (ifp == NULL || ifp->if_ioctl == NULL)
return( EOPNOTSUPP ); return (EOPNOTSUPP);
return( (*ifp->if_ioctl)( ifp, cmd, data )); return ((*ifp->if_ioctl)(ifp, cmd, data));
} }
return( 0 ); return (0);
} }
/* /*
@ -315,32 +315,32 @@ at_control(struct socket *so, u_long cmd, caddr_t data,
* as aa->at_ifaddr.ifa_ifp should be the same. * as aa->at_ifaddr.ifa_ifp should be the same.
*/ */
static int static int
at_scrub( ifp, aa ) at_scrub(ifp, aa)
struct ifnet *ifp; struct ifnet *ifp;
struct at_ifaddr *aa; struct at_ifaddr *aa;
{ {
int error; int error;
if ( aa->aa_flags & AFA_ROUTE ) { if (aa->aa_flags & AFA_ROUTE) {
if (ifp->if_flags & IFF_LOOPBACK) { if (ifp->if_flags & IFF_LOOPBACK) {
if ((error = aa_delsingleroute(&aa->aa_ifa, if ((error = aa_delsingleroute(&aa->aa_ifa,
&aa->aa_addr.sat_addr, &aa->aa_addr.sat_addr,
&aa->aa_netmask.sat_addr)) != 0) { &aa->aa_netmask.sat_addr)) != 0) {
return( error ); return (error);
} }
} else if (ifp->if_flags & IFF_POINTOPOINT) { } else if (ifp->if_flags & IFF_POINTOPOINT) {
if ((error = rtinit( &aa->aa_ifa, RTM_DELETE, RTF_HOST)) != 0) if ((error = rtinit(&aa->aa_ifa, RTM_DELETE, RTF_HOST)) != 0)
return( error ); return (error);
} else if (ifp->if_flags & IFF_BROADCAST) { } else if (ifp->if_flags & IFF_BROADCAST) {
error = aa_dorangeroute(&aa->aa_ifa, error = aa_dorangeroute(&aa->aa_ifa,
ntohs(aa->aa_firstnet), ntohs(aa->aa_firstnet),
ntohs(aa->aa_lastnet), ntohs(aa->aa_lastnet),
RTM_DELETE ); RTM_DELETE);
} }
aa->aa_ifa.ifa_flags &= ~IFA_ROUTE; aa->aa_ifa.ifa_flags &= ~IFA_ROUTE;
aa->aa_flags &= ~AFA_ROUTE; aa->aa_flags &= ~AFA_ROUTE;
} }
return( 0 ); return (0);
} }
/* /*
@ -348,7 +348,7 @@ at_scrub( ifp, aa )
* bang them all together at high speed and see what happens * bang them all together at high speed and see what happens
*/ */
static int static int
at_ifinit( ifp, aa, sat ) at_ifinit(ifp, aa, sat)
struct ifnet *ifp; struct ifnet *ifp;
struct at_ifaddr *aa; struct at_ifaddr *aa;
struct sockaddr_at *sat; struct sockaddr_at *sat;
@ -371,10 +371,10 @@ at_ifinit( ifp, aa, sat )
* at_ifnet (also given). Remember ing to update * at_ifnet (also given). Remember ing to update
* those parts of the at_ifaddr that need special processing * those parts of the at_ifaddr that need special processing
*/ */
bzero( AA_SAT( aa ), sizeof( struct sockaddr_at )); bzero(AA_SAT(aa), sizeof(struct sockaddr_at));
bcopy( sat->sat_zero, &nr, sizeof( struct netrange )); bcopy(sat->sat_zero, &nr, sizeof(struct netrange));
bcopy( sat->sat_zero, AA_SAT( aa )->sat_zero, sizeof( struct netrange )); bcopy(sat->sat_zero, AA_SAT(aa)->sat_zero, sizeof(struct netrange));
nnets = ntohs( nr.nr_lastnet ) - ntohs( nr.nr_firstnet ) + 1; nnets = ntohs(nr.nr_lastnet) - ntohs(nr.nr_firstnet) + 1;
aa->aa_firstnet = nr.nr_firstnet; aa->aa_firstnet = nr.nr_firstnet;
aa->aa_lastnet = nr.nr_lastnet; aa->aa_lastnet = nr.nr_lastnet;
@ -393,13 +393,13 @@ at_ifinit( ifp, aa, sat )
* that phase 1 probes use only nodes, not net.node pairs. Under * that phase 1 probes use only nodes, not net.node pairs. Under
* phase 2, both the net and node must be the same. * phase 2, both the net and node must be the same.
*/ */
if ( ifp->if_flags & IFF_LOOPBACK ) { if (ifp->if_flags & IFF_LOOPBACK) {
AA_SAT( aa )->sat_len = sat->sat_len; AA_SAT(aa)->sat_len = sat->sat_len;
AA_SAT( aa )->sat_family = AF_APPLETALK; AA_SAT(aa)->sat_family = AF_APPLETALK;
AA_SAT( aa )->sat_addr.s_net = sat->sat_addr.s_net; AA_SAT(aa)->sat_addr.s_net = sat->sat_addr.s_net;
AA_SAT( aa )->sat_addr.s_node = sat->sat_addr.s_node; AA_SAT(aa)->sat_addr.s_node = sat->sat_addr.s_node;
#if 0 #if 0
} else if ( fp->if_flags & IFF_POINTOPOINT) { } else if (fp->if_flags & IFF_POINTOPOINT) {
/* unimplemented */ /* unimplemented */
/* /*
* we'd have to copy the dstaddr field over from the sat * we'd have to copy the dstaddr field over from the sat
@ -417,19 +417,19 @@ at_ifinit( ifp, aa, sat )
* we find an unused address. * we find an unused address.
*/ */
aa->aa_flags |= AFA_PROBING; /* if not loopback we Must probe? */ aa->aa_flags |= AFA_PROBING; /* if not loopback we Must probe? */
AA_SAT( aa )->sat_len = sizeof(struct sockaddr_at); AA_SAT(aa)->sat_len = sizeof(struct sockaddr_at);
AA_SAT( aa )->sat_family = AF_APPLETALK; AA_SAT(aa)->sat_family = AF_APPLETALK;
if ( aa->aa_flags & AFA_PHASE2 ) { if (aa->aa_flags & AFA_PHASE2) {
if ( sat->sat_addr.s_net == ATADDR_ANYNET ) { if (sat->sat_addr.s_net == ATADDR_ANYNET) {
/* /*
* If we are phase 2, and the net was not specified * If we are phase 2, and the net was not specified
* then we select a random net within the supplied netrange. * then we select a random net within the supplied netrange.
* XXX use /dev/random? * XXX use /dev/random?
*/ */
if ( nnets != 1 ) { if (nnets != 1) {
net = ntohs( nr.nr_firstnet ) + time_second % ( nnets - 1 ); net = ntohs(nr.nr_firstnet) + time_second % (nnets - 1);
} else { } else {
net = ntohs( nr.nr_firstnet ); net = ntohs(nr.nr_firstnet);
} }
} else { } else {
/* /*
@ -437,25 +437,25 @@ at_ifinit( ifp, aa, sat )
* the netrange. If it is not then replace the old values * the netrange. If it is not then replace the old values
* and return an error * and return an error
*/ */
if ( ntohs( sat->sat_addr.s_net ) < ntohs( nr.nr_firstnet ) || if (ntohs(sat->sat_addr.s_net) < ntohs(nr.nr_firstnet) ||
ntohs( sat->sat_addr.s_net ) > ntohs( nr.nr_lastnet )) { ntohs(sat->sat_addr.s_net) > ntohs(nr.nr_lastnet)) {
aa->aa_addr = oldaddr; aa->aa_addr = oldaddr;
aa->aa_firstnet = onr.nr_firstnet; aa->aa_firstnet = onr.nr_firstnet;
aa->aa_lastnet = onr.nr_lastnet; aa->aa_lastnet = onr.nr_lastnet;
splx(s); splx(s);
return( EINVAL ); return (EINVAL);
} }
/* /*
* otherwise just use the new net number.. * otherwise just use the new net number..
*/ */
net = ntohs( sat->sat_addr.s_net ); net = ntohs(sat->sat_addr.s_net);
} }
} else { } else {
/* /*
* we must be phase one, so just use whatever we were given. * we must be phase one, so just use whatever we were given.
* I guess it really isn't going to be used... RIGHT? * I guess it really isn't going to be used... RIGHT?
*/ */
net = ntohs( sat->sat_addr.s_net ); net = ntohs(sat->sat_addr.s_net);
} }
/* /*
@ -463,25 +463,25 @@ at_ifinit( ifp, aa, sat )
* If it's not specified, be random about it... * If it's not specified, be random about it...
* XXX use /dev/random? * XXX use /dev/random?
*/ */
if ( sat->sat_addr.s_node == ATADDR_ANYNODE ) { if (sat->sat_addr.s_node == ATADDR_ANYNODE) {
AA_SAT( aa )->sat_addr.s_node = time_second; AA_SAT(aa)->sat_addr.s_node = time_second;
} else { } else {
AA_SAT( aa )->sat_addr.s_node = sat->sat_addr.s_node; AA_SAT(aa)->sat_addr.s_node = sat->sat_addr.s_node;
} }
/* /*
* Copy the phase. * Copy the phase.
*/ */
AA_SAT( aa )->sat_range.r_netrange.nr_phase AA_SAT(aa)->sat_range.r_netrange.nr_phase
= ((aa->aa_flags & AFA_PHASE2) ? 2:1); = ((aa->aa_flags & AFA_PHASE2) ? 2:1);
/* /*
* step through the nets in the range * step through the nets in the range
* starting at the (possibly random) start point. * starting at the (possibly random) start point.
*/ */
for ( i = nnets, netinc = 1; i > 0; net = ntohs( nr.nr_firstnet ) + for (i = nnets, netinc = 1; i > 0; net = ntohs(nr.nr_firstnet) +
(( net - ntohs( nr.nr_firstnet ) + netinc ) % nnets ), i-- ) { ((net - ntohs(nr.nr_firstnet) + netinc) % nnets), i--) {
AA_SAT( aa )->sat_addr.s_net = htons( net ); AA_SAT(aa)->sat_addr.s_net = htons(net);
/* /*
* using a rather strange stepping method, * using a rather strange stepping method,
@ -489,10 +489,10 @@ at_ifinit( ifp, aa, sat )
* Once again, starting at the (possibly random) * Once again, starting at the (possibly random)
* initial node address. * initial node address.
*/ */
for ( j = 0, nodeinc = time_second | 1; j < 256; for (j = 0, nodeinc = time_second | 1; j < 256;
j++, AA_SAT( aa )->sat_addr.s_node += nodeinc ) { j++, AA_SAT(aa)->sat_addr.s_node += nodeinc) {
if ( AA_SAT( aa )->sat_addr.s_node > 253 || if (AA_SAT(aa)->sat_addr.s_node > 253 ||
AA_SAT( aa )->sat_addr.s_node < 1 ) { AA_SAT(aa)->sat_addr.s_node < 1) {
continue; continue;
} }
aa->aa_probcnt = 10; aa->aa_probcnt = 10;
@ -501,18 +501,18 @@ at_ifinit( ifp, aa, sat )
* start off the probes as an asynchronous activity. * start off the probes as an asynchronous activity.
* though why wait 200mSec? * though why wait 200mSec?
*/ */
aa->aa_ch = timeout( aarpprobe, (caddr_t)ifp, hz / 5 ); aa->aa_ch = timeout(aarpprobe, (caddr_t)ifp, hz / 5);
if ( tsleep( aa, PPAUSE|PCATCH, "at_ifinit", 0 )) { if (tsleep(aa, PPAUSE|PCATCH, "at_ifinit", 0)) {
/* /*
* theoretically we shouldn't time out here * theoretically we shouldn't time out here
* so if we returned with an error.. * so if we returned with an error..
*/ */
printf( "at_ifinit: why did this happen?!\n" ); printf("at_ifinit: why did this happen?!\n");
aa->aa_addr = oldaddr; aa->aa_addr = oldaddr;
aa->aa_firstnet = onr.nr_firstnet; aa->aa_firstnet = onr.nr_firstnet;
aa->aa_lastnet = onr.nr_lastnet; aa->aa_lastnet = onr.nr_lastnet;
splx( s ); splx(s);
return( EINTR ); return (EINTR);
} }
/* /*
@ -521,7 +521,7 @@ at_ifinit( ifp, aa, sat )
* a free spot, or if we need to iterate to the next * a free spot, or if we need to iterate to the next
* address to try. * address to try.
*/ */
if (( aa->aa_flags & AFA_PROBING ) == 0 ) { if ((aa->aa_flags & AFA_PROBING) == 0) {
break; break;
} }
} }
@ -529,11 +529,11 @@ at_ifinit( ifp, aa, sat )
/* /*
* of course we need to break out through two loops... * of course we need to break out through two loops...
*/ */
if (( aa->aa_flags & AFA_PROBING ) == 0 ) { if ((aa->aa_flags & AFA_PROBING) == 0) {
break; break;
} }
/* reset node for next network */ /* reset node for next network */
AA_SAT( aa )->sat_addr.s_node = time_second; AA_SAT(aa)->sat_addr.s_node = time_second;
} }
/* /*
@ -541,12 +541,12 @@ at_ifinit( ifp, aa, sat )
* the possible addresses, so we need to give up * the possible addresses, so we need to give up
*/ */
if ( aa->aa_flags & AFA_PROBING ) { if (aa->aa_flags & AFA_PROBING) {
aa->aa_addr = oldaddr; aa->aa_addr = oldaddr;
aa->aa_firstnet = onr.nr_firstnet; aa->aa_firstnet = onr.nr_firstnet;
aa->aa_lastnet = onr.nr_lastnet; aa->aa_lastnet = onr.nr_lastnet;
splx( s ); splx(s);
return( EADDRINUSE ); return (EADDRINUSE);
} }
} }
@ -554,8 +554,8 @@ at_ifinit( ifp, aa, sat )
* Now that we have selected an address, we need to tell the interface * Now that we have selected an address, we need to tell the interface
* about it, just in case it needs to adjust something. * about it, just in case it needs to adjust something.
*/ */
if ( ifp->if_ioctl && if (ifp->if_ioctl &&
( error = (*ifp->if_ioctl)( ifp, SIOCSIFADDR, (caddr_t)aa ))) { (error = (*ifp->if_ioctl)(ifp, SIOCSIFADDR, (caddr_t)aa))) {
/* /*
* of course this could mean that it objects violently * of course this could mean that it objects violently
* so if it does, we back out again.. * so if it does, we back out again..
@ -563,8 +563,8 @@ at_ifinit( ifp, aa, sat )
aa->aa_addr = oldaddr; aa->aa_addr = oldaddr;
aa->aa_firstnet = onr.nr_firstnet; aa->aa_firstnet = onr.nr_firstnet;
aa->aa_lastnet = onr.nr_lastnet; aa->aa_lastnet = onr.nr_lastnet;
splx( s ); splx(s);
return( error ); return (error);
} }
/* /*
@ -590,10 +590,10 @@ at_ifinit( ifp, aa, sat )
if (ifp->if_flags & IFF_BROADCAST) { if (ifp->if_flags & IFF_BROADCAST) {
aa->aa_broadaddr.sat_addr.s_net = htons(0); aa->aa_broadaddr.sat_addr.s_net = htons(0);
aa->aa_broadaddr.sat_addr.s_node = 0xff; aa->aa_broadaddr.sat_addr.s_node = 0xff;
aa->aa_ifa.ifa_broadaddr = (struct sockaddr *) &aa->aa_broadaddr; aa->aa_ifa.ifa_broadaddr = (struct sockaddr *) &aa->aa_broadaddr;
/* add the range of routes needed */ /* add the range of routes needed */
error = aa_dorangeroute(&aa->aa_ifa, error = aa_dorangeroute(&aa->aa_ifa,
ntohs(aa->aa_firstnet), ntohs(aa->aa_lastnet), RTM_ADD ); ntohs(aa->aa_firstnet), ntohs(aa->aa_lastnet), RTM_ADD);
} }
else if (ifp->if_flags & IFF_POINTOPOINT) { else if (ifp->if_flags & IFF_POINTOPOINT) {
struct at_addr rtaddr, rtmask; struct at_addr rtaddr, rtmask;
@ -601,16 +601,16 @@ at_ifinit( ifp, aa, sat )
bzero(&rtaddr, sizeof(rtaddr)); bzero(&rtaddr, sizeof(rtaddr));
bzero(&rtmask, sizeof(rtmask)); bzero(&rtmask, sizeof(rtmask));
/* fill in the far end if we know it here XXX */ /* fill in the far end if we know it here XXX */
aa->aa_ifa.ifa_dstaddr = (struct sockaddr *) &aa->aa_dstaddr; aa->aa_ifa.ifa_dstaddr = (struct sockaddr *) &aa->aa_dstaddr;
error = aa_addsingleroute(&aa->aa_ifa, &rtaddr, &rtmask); error = aa_addsingleroute(&aa->aa_ifa, &rtaddr, &rtmask);
} }
else if ( ifp->if_flags & IFF_LOOPBACK ) { else if (ifp->if_flags & IFF_LOOPBACK) {
struct at_addr rtaddr, rtmask; struct at_addr rtaddr, rtmask;
bzero(&rtaddr, sizeof(rtaddr)); bzero(&rtaddr, sizeof(rtaddr));
bzero(&rtmask, sizeof(rtmask)); bzero(&rtmask, sizeof(rtmask));
rtaddr.s_net = AA_SAT( aa )->sat_addr.s_net; rtaddr.s_net = AA_SAT(aa)->sat_addr.s_net;
rtaddr.s_node = AA_SAT( aa )->sat_addr.s_node; rtaddr.s_node = AA_SAT(aa)->sat_addr.s_node;
rtmask.s_net = 0xffff; rtmask.s_net = 0xffff;
rtmask.s_node = 0x0; /* XXX should not be so.. should be HOST route */ rtmask.s_node = 0x0; /* XXX should not be so.. should be HOST route */
error = aa_addsingleroute(&aa->aa_ifa, &rtaddr, &rtmask); error = aa_addsingleroute(&aa->aa_ifa, &rtaddr, &rtmask);
@ -626,13 +626,13 @@ at_ifinit( ifp, aa, sat )
* of course if we can't add these routes we back out, but it's getting * of course if we can't add these routes we back out, but it's getting
* risky by now XXX * risky by now XXX
*/ */
if ( error ) { if (error) {
at_scrub( ifp, aa ); at_scrub(ifp, aa);
aa->aa_addr = oldaddr; aa->aa_addr = oldaddr;
aa->aa_firstnet = onr.nr_firstnet; aa->aa_firstnet = onr.nr_firstnet;
aa->aa_lastnet = onr.nr_lastnet; aa->aa_lastnet = onr.nr_lastnet;
splx( s ); splx(s);
return( error ); return (error);
} }
/* /*
@ -640,15 +640,15 @@ at_ifinit( ifp, aa, sat )
*/ */
aa->aa_ifa.ifa_flags |= IFA_ROUTE; aa->aa_ifa.ifa_flags |= IFA_ROUTE;
aa->aa_flags |= AFA_ROUTE; aa->aa_flags |= AFA_ROUTE;
splx( s ); splx(s);
return( 0 ); return (0);
} }
/* /*
* check whether a given address is a broadcast address for us.. * check whether a given address is a broadcast address for us..
*/ */
int int
at_broadcast( sat ) at_broadcast(sat)
struct sockaddr_at *sat; struct sockaddr_at *sat;
{ {
struct at_ifaddr *aa; struct at_ifaddr *aa;
@ -656,28 +656,28 @@ at_broadcast( sat )
/* /*
* If the node is not right, it can't be a broadcast * If the node is not right, it can't be a broadcast
*/ */
if ( sat->sat_addr.s_node != ATADDR_BCAST ) { if (sat->sat_addr.s_node != ATADDR_BCAST) {
return( 0 ); return (0);
} }
/* /*
* If the node was right then if the net is right, it's a broadcast * If the node was right then if the net is right, it's a broadcast
*/ */
if ( sat->sat_addr.s_net == ATADDR_ANYNET ) { if (sat->sat_addr.s_net == ATADDR_ANYNET) {
return( 1 ); return (1);
} }
/* /*
* failing that, if the net is one we have, it's a broadcast as well. * failing that, if the net is one we have, it's a broadcast as well.
*/ */
for ( aa = at_ifaddr; aa; aa = aa->aa_next ) { for (aa = at_ifaddr; aa; aa = aa->aa_next) {
if (( aa->aa_ifp->if_flags & IFF_BROADCAST ) if ((aa->aa_ifp->if_flags & IFF_BROADCAST)
&& ( ntohs( sat->sat_addr.s_net ) >= ntohs( aa->aa_firstnet ) && (ntohs(sat->sat_addr.s_net) >= ntohs(aa->aa_firstnet)
&& ntohs( sat->sat_addr.s_net ) <= ntohs( aa->aa_lastnet ))) { && ntohs(sat->sat_addr.s_net) <= ntohs(aa->aa_lastnet))) {
return( 1 ); return (1);
} }
} }
return( 0 ); return (0);
} }
/* /*
@ -717,8 +717,8 @@ aa_dorangeroute(struct ifaddr *ifa, u_int bot, u_int top, int cmd)
while (bot <= top) { while (bot <= top) {
mask1 = 1; mask1 = 1;
while ((( bot & ~mask1) >= bot) while (((bot & ~mask1) >= bot)
&& (( bot | mask1) <= top)) { && ((bot | mask1) <= top)) {
mask1 <<= 1; mask1 <<= 1;
mask1 |= 1; mask1 |= 1;
} }
@ -736,7 +736,7 @@ aa_dorangeroute(struct ifaddr *ifa, u_int bot, u_int top, int cmd)
} }
bot = (bot | mask1) + 1; bot = (bot | mask1) + 1;
} }
return 0; return (0);
} }
static int static int
@ -754,7 +754,7 @@ aa_addsingleroute(struct ifaddr *ifa,
error = aa_dosingleroute(ifa, addr, mask, RTM_ADD, RTF_UP); error = aa_dosingleroute(ifa, addr, mask, RTM_ADD, RTF_UP);
if (error) if (error)
printf("aa_addsingleroute: error %d\n", error); printf("aa_addsingleroute: error %d\n", error);
return(error); return (error);
} }
static int static int
@ -766,7 +766,7 @@ aa_delsingleroute(struct ifaddr *ifa,
error = aa_dosingleroute(ifa, addr, mask, RTM_DELETE, 0); error = aa_dosingleroute(ifa, addr, mask, RTM_DELETE, 0);
if (error) if (error)
printf("aa_delsingleroute: error %d\n", error); printf("aa_delsingleroute: error %d\n", error);
return(error); return (error);
} }
static int static int
@ -787,7 +787,7 @@ aa_dosingleroute(struct ifaddr *ifa,
mask.sat_addr.s_node = at_mask->s_node; mask.sat_addr.s_node = at_mask->s_node;
if (at_mask->s_node) if (at_mask->s_node)
flags |= RTF_HOST; flags |= RTF_HOST;
return(rtrequest(cmd, (struct sockaddr *) &addr, return (rtrequest(cmd, (struct sockaddr *) &addr,
(flags & RTF_HOST)?(ifa->ifa_dstaddr):(ifa->ifa_addr), (flags & RTF_HOST)?(ifa->ifa_dstaddr):(ifa->ifa_addr),
(struct sockaddr *) &mask, flags, NULL)); (struct sockaddr *) &mask, flags, NULL));
} }
@ -801,21 +801,21 @@ aa_clean(void)
struct ifaddr *ifa; struct ifaddr *ifa;
struct ifnet *ifp; struct ifnet *ifp;
while ( aa = at_ifaddr ) { while (aa = at_ifaddr) {
ifp = aa->aa_ifp; ifp = aa->aa_ifp;
at_scrub( ifp, aa ); at_scrub(ifp, aa);
at_ifaddr = aa->aa_next; at_ifaddr = aa->aa_next;
if (( ifa = ifp->if_addrlist ) == (struct ifaddr *)aa ) { if ((ifa = ifp->if_addrlist) == (struct ifaddr *)aa) {
ifp->if_addrlist = ifa->ifa_next; ifp->if_addrlist = ifa->ifa_next;
} else { } else {
while ( ifa->ifa_next && while (ifa->ifa_next &&
( ifa->ifa_next != (struct ifaddr *)aa )) { (ifa->ifa_next != (struct ifaddr *)aa)) {
ifa = ifa->ifa_next; ifa = ifa->ifa_next;
} }
if ( ifa->ifa_next ) { if (ifa->ifa_next) {
ifa->ifa_next = ((struct ifaddr *)aa)->ifa_next; ifa->ifa_next = ((struct ifaddr *)aa)->ifa_next;
} else { } else {
panic( "at_entry" ); panic("at_entry");
} }
} }
} }
@ -832,7 +832,7 @@ aa_claim_addr(struct ifaddr *ifa, struct sockaddr *gw0)
switch (gw->sat_range.r_netrange.nr_phase) { switch (gw->sat_range.r_netrange.nr_phase) {
case 1: case 1:
if(addr->sat_range.r_netrange.nr_phase == 1) if(addr->sat_range.r_netrange.nr_phase == 1)
return 1; return (1);
case 0: case 0:
case 2: case 2:
/* /*
@ -843,14 +843,14 @@ aa_claim_addr(struct ifaddr *ifa, struct sockaddr *gw0)
if ((addr->sat_addr.s_net == gw->sat_addr.s_net) if ((addr->sat_addr.s_net == gw->sat_addr.s_net)
|| ((addr->sat_range.r_netrange.nr_lastnet) || ((addr->sat_range.r_netrange.nr_lastnet)
&& (ntohs(gw->sat_addr.s_net) && (ntohs(gw->sat_addr.s_net)
>= ntohs(addr->sat_range.r_netrange.nr_firstnet )) >= ntohs(addr->sat_range.r_netrange.nr_firstnet))
&& (ntohs(gw->sat_addr.s_net) && (ntohs(gw->sat_addr.s_net)
<= ntohs(addr->sat_range.r_netrange.nr_lastnet )))) { <= ntohs(addr->sat_range.r_netrange.nr_lastnet)))) {
return 1; return (1);
} }
break; break;
default: default:
printf("atalk: bad phase\n"); printf("atalk: bad phase\n");
} }
return 0; return (0);
} }

View file

@ -46,20 +46,20 @@
int ddp_cksum = 1; int ddp_cksum = 1;
int int
ddp_output( struct mbuf *m, struct socket *so) ddp_output(struct mbuf *m, struct socket *so)
{ {
struct ddpehdr *deh; struct ddpehdr *deh;
struct ddpcb *ddp = sotoddpcb( so ); struct ddpcb *ddp = sotoddpcb(so);
#ifdef MAC #ifdef MAC
mac_create_mbuf_from_socket(so, m); mac_create_mbuf_from_socket(so, m);
#endif #endif
M_PREPEND( m, sizeof( struct ddpehdr ), M_TRYWAIT ); M_PREPEND(m, sizeof(struct ddpehdr), M_TRYWAIT);
if ( m == NULL ) if (m == NULL)
return( ENOBUFS ); return (ENOBUFS);
deh = mtod( m, struct ddpehdr *); deh = mtod(m, struct ddpehdr *);
deh->deh_pad = 0; deh->deh_pad = 0;
deh->deh_hops = 0; deh->deh_hops = 0;
@ -76,50 +76,50 @@ ddp_output( struct mbuf *m, struct socket *so)
* The checksum calculation is done after all of the other bytes have * The checksum calculation is done after all of the other bytes have
* been filled in. * been filled in.
*/ */
if ( ddp_cksum ) { if (ddp_cksum) {
deh->deh_sum = at_cksum( m, sizeof( int )); deh->deh_sum = at_cksum(m, sizeof(int));
} else { } else {
deh->deh_sum = 0; deh->deh_sum = 0;
} }
deh->deh_bytes = htonl( deh->deh_bytes ); deh->deh_bytes = htonl(deh->deh_bytes);
#ifdef NETATALK_DEBUG #ifdef NETATALK_DEBUG
printf ("ddp_output: from %d.%d:%d to %d.%d:%d\n", printf ("ddp_output: from %d.%d:%d to %d.%d:%d\n",
ntohs(deh->deh_snet), deh->deh_snode, deh->deh_sport, ntohs(deh->deh_snet), deh->deh_snode, deh->deh_sport,
ntohs(deh->deh_dnet), deh->deh_dnode, deh->deh_dport); ntohs(deh->deh_dnet), deh->deh_dnode, deh->deh_dport);
#endif #endif
return( ddp_route( m, &ddp->ddp_route )); return (ddp_route(m, &ddp->ddp_route));
} }
u_short u_short
at_cksum( struct mbuf *m, int skip) at_cksum(struct mbuf *m, int skip)
{ {
u_char *data, *end; u_char *data, *end;
u_long cksum = 0; u_long cksum = 0;
for (; m; m = m->m_next ) { for (; m; m = m->m_next) {
for ( data = mtod( m, u_char * ), end = data + m->m_len; data < end; for (data = mtod(m, u_char *), end = data + m->m_len; data < end;
data++ ) { data++) {
if ( skip ) { if (skip) {
skip--; skip--;
continue; continue;
} }
cksum = ( cksum + *data ) << 1; cksum = (cksum + *data) << 1;
if ( cksum & 0x00010000 ) { if (cksum & 0x00010000) {
cksum++; cksum++;
} }
cksum &= 0x0000ffff; cksum &= 0x0000ffff;
} }
} }
if ( cksum == 0 ) { if (cksum == 0) {
cksum = 0x0000ffff; cksum = 0x0000ffff;
} }
return( (u_short)cksum ); return ((u_short)cksum);
} }
int int
ddp_route( struct mbuf *m, struct route *ro) ddp_route(struct mbuf *m, struct route *ro)
{ {
struct sockaddr_at gate; struct sockaddr_at gate;
struct elaphdr *elh; struct elaphdr *elh;
@ -140,24 +140,24 @@ ddp_route( struct mbuf *m, struct route *ro)
* if we have a route, find the ifa that refers to this route. * if we have a route, find the ifa that refers to this route.
* I.e The ifa used to get to the gateway. * I.e The ifa used to get to the gateway.
*/ */
if ( (ro->ro_rt == NULL) if ((ro->ro_rt == NULL)
|| ( ro->ro_rt->rt_ifa == NULL ) || (ro->ro_rt->rt_ifa == NULL)
|| ( (ifp = ro->ro_rt->rt_ifa->ifa_ifp) == NULL )) { || ((ifp = ro->ro_rt->rt_ifa->ifa_ifp) == NULL)) {
rtalloc(ro); rtalloc(ro);
} }
if ( (ro->ro_rt != NULL) if ((ro->ro_rt != NULL)
&& ( ro->ro_rt->rt_ifa ) && (ro->ro_rt->rt_ifa)
&& ( ifp = ro->ro_rt->rt_ifa->ifa_ifp )) { && (ifp = ro->ro_rt->rt_ifa->ifa_ifp)) {
net = ntohs(satosat(ro->ro_rt->rt_gateway)->sat_addr.s_net); net = ntohs(satosat(ro->ro_rt->rt_gateway)->sat_addr.s_net);
for ( aa = at_ifaddr; aa; aa = aa->aa_next ) { for (aa = at_ifaddr; aa; aa = aa->aa_next) {
if (((net == 0) || (aa->aa_ifp == ifp)) && if (((net == 0) || (aa->aa_ifp == ifp)) &&
net >= ntohs( aa->aa_firstnet ) && net >= ntohs(aa->aa_firstnet) &&
net <= ntohs( aa->aa_lastnet )) { net <= ntohs(aa->aa_lastnet)) {
break; break;
} }
} }
} else { } else {
m_freem( m ); m_freem(m);
#ifdef NETATALK_DEBUG #ifdef NETATALK_DEBUG
if (ro->ro_rt == NULL) if (ro->ro_rt == NULL)
printf ("ddp_route: no ro_rt.\n"); printf ("ddp_route: no ro_rt.\n");
@ -166,29 +166,29 @@ ddp_route( struct mbuf *m, struct route *ro)
else else
printf ("ddp_route: no ro_rt->rt_ifa->ifa_ifp\n"); printf ("ddp_route: no ro_rt->rt_ifa->ifa_ifp\n");
#endif #endif
return( ENETUNREACH ); return (ENETUNREACH);
} }
if ( aa == NULL ) { if (aa == NULL) {
#ifdef NETATALK_DEBUG #ifdef NETATALK_DEBUG
printf( "ddp_route: no atalk address found for %s\n", printf("ddp_route: no atalk address found for %s\n",
ifp->if_xname); ifp->if_xname);
#endif #endif
m_freem( m ); m_freem(m);
return( ENETUNREACH ); return (ENETUNREACH);
} }
/* /*
* if the destination address is on a directly attached node use that, * if the destination address is on a directly attached node use that,
* else use the official gateway. * else use the official gateway.
*/ */
if ( ntohs( satosat( &ro->ro_dst )->sat_addr.s_net ) >= if (ntohs(satosat(&ro->ro_dst)->sat_addr.s_net) >=
ntohs( aa->aa_firstnet ) && ntohs(aa->aa_firstnet) &&
ntohs( satosat( &ro->ro_dst )->sat_addr.s_net ) <= ntohs(satosat(&ro->ro_dst)->sat_addr.s_net) <=
ntohs( aa->aa_lastnet )) { ntohs(aa->aa_lastnet)) {
gate = *satosat( &ro->ro_dst ); gate = *satosat(&ro->ro_dst);
} else { } else {
gate = *satosat( ro->ro_rt->rt_gateway ); gate = *satosat(ro->ro_rt->rt_gateway);
} }
/* /*
@ -197,12 +197,12 @@ ddp_route( struct mbuf *m, struct route *ro)
* This is bad for transition routing, since phase 1 and phase 2 * This is bad for transition routing, since phase 1 and phase 2
* packets end up poorly aligned due to the three byte elap header. * packets end up poorly aligned due to the three byte elap header.
*/ */
if ( !(aa->aa_flags & AFA_PHASE2) ) { if (!(aa->aa_flags & AFA_PHASE2)) {
MGET( m0, M_TRYWAIT, MT_HEADER ); MGET(m0, M_TRYWAIT, MT_HEADER);
if ( m0 == NULL ) { if (m0 == NULL) {
m_freem( m ); m_freem(m);
printf("ddp_route: no buffers\n"); printf("ddp_route: no buffers\n");
return( ENOBUFS ); return (ENOBUFS);
} }
#ifdef MAC #ifdef MAC
mac_create_mbuf_from_mbuf(m, m0); mac_create_mbuf_from_mbuf(m, m0);
@ -212,8 +212,8 @@ ddp_route( struct mbuf *m, struct route *ro)
m0->m_len = SZ_ELAPHDR; m0->m_len = SZ_ELAPHDR;
m = m0; m = m0;
elh = mtod( m, struct elaphdr *); elh = mtod(m, struct elaphdr *);
elh->el_snode = satosat( &aa->aa_addr )->sat_addr.s_node; elh->el_snode = satosat(&aa->aa_addr)->sat_addr.s_node;
elh->el_type = ELAP_DDPEXTEND; elh->el_type = ELAP_DDPEXTEND;
elh->el_dnode = gate.sat_addr.s_node; elh->el_dnode = gate.sat_addr.s_node;
} }
@ -237,6 +237,6 @@ ddp_route( struct mbuf *m, struct route *ro)
return (if_simloop(ifp, m, gate.sat_family, 0)); return (if_simloop(ifp, m, gate.sat_family, 0));
} }
return((*ifp->if_output)( ifp, return ((*ifp->if_output)(ifp,
m, (struct sockaddr *)&gate, NULL)); /* XXX */ m, (struct sockaddr *)&gate, NULL)); /* XXX */
} }

View file

@ -38,41 +38,41 @@ at_pcbsetaddr(struct ddpcb *ddp, struct sockaddr *addr, struct thread *td)
struct at_ifaddr *aa; struct at_ifaddr *aa;
struct ddpcb *ddpp; struct ddpcb *ddpp;
if ( ddp->ddp_lsat.sat_port != ATADDR_ANYPORT ) { /* shouldn't be bound */ if (ddp->ddp_lsat.sat_port != ATADDR_ANYPORT) { /* shouldn't be bound */
return( EINVAL ); return (EINVAL);
} }
if (addr != NULL) { /* validate passed address */ if (addr != NULL) { /* validate passed address */
sat = (struct sockaddr_at *)addr; sat = (struct sockaddr_at *)addr;
if (sat->sat_family != AF_APPLETALK) { if (sat->sat_family != AF_APPLETALK) {
return(EAFNOSUPPORT); return (EAFNOSUPPORT);
} }
if ( sat->sat_addr.s_node != ATADDR_ANYNODE || if (sat->sat_addr.s_node != ATADDR_ANYNODE ||
sat->sat_addr.s_net != ATADDR_ANYNET ) { sat->sat_addr.s_net != ATADDR_ANYNET) {
for ( aa = at_ifaddr; aa; aa = aa->aa_next ) { for (aa = at_ifaddr; aa; aa = aa->aa_next) {
if (( sat->sat_addr.s_net == AA_SAT( aa )->sat_addr.s_net ) && if ((sat->sat_addr.s_net == AA_SAT(aa)->sat_addr.s_net) &&
( sat->sat_addr.s_node == AA_SAT( aa )->sat_addr.s_node )) { (sat->sat_addr.s_node == AA_SAT(aa)->sat_addr.s_node)) {
break; break;
} }
} }
if ( !aa ) { if (!aa) {
return( EADDRNOTAVAIL ); return (EADDRNOTAVAIL);
} }
} }
if ( sat->sat_port != ATADDR_ANYPORT ) { if (sat->sat_port != ATADDR_ANYPORT) {
if ( sat->sat_port < ATPORT_FIRST || if (sat->sat_port < ATPORT_FIRST ||
sat->sat_port >= ATPORT_LAST ) { sat->sat_port >= ATPORT_LAST) {
return( EINVAL ); return (EINVAL);
} }
if ( sat->sat_port < ATPORT_RESERVED && if (sat->sat_port < ATPORT_RESERVED &&
suser(td) ) { suser(td)) {
return( EACCES ); return (EACCES);
} }
} }
} else { } else {
bzero( (caddr_t)&lsat, sizeof( struct sockaddr_at )); bzero((caddr_t)&lsat, sizeof(struct sockaddr_at));
lsat.sat_len = sizeof(struct sockaddr_at); lsat.sat_len = sizeof(struct sockaddr_at);
lsat.sat_addr.s_node = ATADDR_ANYNODE; lsat.sat_addr.s_node = ATADDR_ANYNODE;
lsat.sat_addr.s_net = ATADDR_ANYNET; lsat.sat_addr.s_net = ATADDR_ANYNET;
@ -80,49 +80,49 @@ at_pcbsetaddr(struct ddpcb *ddp, struct sockaddr *addr, struct thread *td)
sat = &lsat; sat = &lsat;
} }
if ( sat->sat_addr.s_node == ATADDR_ANYNODE && if (sat->sat_addr.s_node == ATADDR_ANYNODE &&
sat->sat_addr.s_net == ATADDR_ANYNET ) { sat->sat_addr.s_net == ATADDR_ANYNET) {
if ( at_ifaddr == NULL ) { if (at_ifaddr == NULL) {
return( EADDRNOTAVAIL ); return (EADDRNOTAVAIL);
} }
sat->sat_addr = AA_SAT( at_ifaddr )->sat_addr; sat->sat_addr = AA_SAT(at_ifaddr)->sat_addr;
} }
ddp->ddp_lsat = *sat; ddp->ddp_lsat = *sat;
/* /*
* Choose port. * Choose port.
*/ */
if ( sat->sat_port == ATADDR_ANYPORT ) { if (sat->sat_port == ATADDR_ANYPORT) {
for ( sat->sat_port = ATPORT_RESERVED; for (sat->sat_port = ATPORT_RESERVED;
sat->sat_port < ATPORT_LAST; sat->sat_port++ ) { sat->sat_port < ATPORT_LAST; sat->sat_port++) {
if ( ddp_ports[ sat->sat_port - 1 ] == NULL ) { if (ddp_ports[ sat->sat_port - 1 ] == NULL) {
break; break;
} }
} }
if ( sat->sat_port == ATPORT_LAST ) { if (sat->sat_port == ATPORT_LAST) {
return( EADDRNOTAVAIL ); return (EADDRNOTAVAIL);
} }
ddp->ddp_lsat.sat_port = sat->sat_port; ddp->ddp_lsat.sat_port = sat->sat_port;
ddp_ports[ sat->sat_port - 1 ] = ddp; ddp_ports[ sat->sat_port - 1 ] = ddp;
} else { } else {
for ( ddpp = ddp_ports[ sat->sat_port - 1 ]; ddpp; for (ddpp = ddp_ports[ sat->sat_port - 1 ]; ddpp;
ddpp = ddpp->ddp_pnext ) { ddpp = ddpp->ddp_pnext) {
if ( ddpp->ddp_lsat.sat_addr.s_net == sat->sat_addr.s_net && if (ddpp->ddp_lsat.sat_addr.s_net == sat->sat_addr.s_net &&
ddpp->ddp_lsat.sat_addr.s_node == sat->sat_addr.s_node ) { ddpp->ddp_lsat.sat_addr.s_node == sat->sat_addr.s_node) {
break; break;
} }
} }
if ( ddpp != NULL ) { if (ddpp != NULL) {
return( EADDRINUSE ); return (EADDRINUSE);
} }
ddp->ddp_pnext = ddp_ports[ sat->sat_port - 1 ]; ddp->ddp_pnext = ddp_ports[ sat->sat_port - 1 ];
ddp_ports[ sat->sat_port - 1 ] = ddp; ddp_ports[ sat->sat_port - 1 ] = ddp;
if ( ddp->ddp_pnext ) { if (ddp->ddp_pnext) {
ddp->ddp_pnext->ddp_pprev = ddp; ddp->ddp_pnext->ddp_pprev = ddp;
} }
} }
return( 0 ); return (0);
} }
int int
@ -135,7 +135,7 @@ at_pcbconnect(struct ddpcb *ddp, struct sockaddr *addr, struct thread *td)
u_short hintnet = 0, net; u_short hintnet = 0, net;
if (sat->sat_family != AF_APPLETALK) { if (sat->sat_family != AF_APPLETALK) {
return(EAFNOSUPPORT); return (EAFNOSUPPORT);
} }
/* /*
@ -143,10 +143,10 @@ at_pcbconnect(struct ddpcb *ddp, struct sockaddr *addr, struct thread *td)
* network" to mean the network the control block is bound to. * network" to mean the network the control block is bound to.
* If the control block is not bound, there is an error. * If the control block is not bound, there is an error.
*/ */
if ( sat->sat_addr.s_net == ATADDR_ANYNET if (sat->sat_addr.s_net == ATADDR_ANYNET
&& sat->sat_addr.s_node != ATADDR_ANYNODE ) { && sat->sat_addr.s_node != ATADDR_ANYNODE) {
if ( ddp->ddp_lsat.sat_port == ATADDR_ANYPORT ) { if (ddp->ddp_lsat.sat_port == ATADDR_ANYPORT) {
return( EADDRNOTAVAIL ); return (EADDRNOTAVAIL);
} }
hintnet = ddp->ddp_lsat.sat_addr.s_net; hintnet = ddp->ddp_lsat.sat_addr.s_net;
} }
@ -157,27 +157,27 @@ at_pcbconnect(struct ddpcb *ddp, struct sockaddr *addr, struct thread *td)
* If we've changed our address, we may have an old "good looking" * If we've changed our address, we may have an old "good looking"
* route here. Attempt to detect it. * route here. Attempt to detect it.
*/ */
if ( ro->ro_rt ) { if (ro->ro_rt) {
if ( hintnet ) { if (hintnet) {
net = hintnet; net = hintnet;
} else { } else {
net = sat->sat_addr.s_net; net = sat->sat_addr.s_net;
} }
aa = NULL; aa = NULL;
if ((ifp = ro->ro_rt->rt_ifp) != NULL) { if ((ifp = ro->ro_rt->rt_ifp) != NULL) {
for ( aa = at_ifaddr; aa; aa = aa->aa_next ) { for (aa = at_ifaddr; aa; aa = aa->aa_next) {
if ( aa->aa_ifp == ifp && if (aa->aa_ifp == ifp &&
ntohs( net ) >= ntohs( aa->aa_firstnet ) && ntohs(net) >= ntohs(aa->aa_firstnet) &&
ntohs( net ) <= ntohs( aa->aa_lastnet )) { ntohs(net) <= ntohs(aa->aa_lastnet)) {
break; break;
} }
} }
} }
if ( aa == NULL || ( satosat( &ro->ro_dst )->sat_addr.s_net != if (aa == NULL || (satosat(&ro->ro_dst)->sat_addr.s_net !=
( hintnet ? hintnet : sat->sat_addr.s_net ) || (hintnet ? hintnet : sat->sat_addr.s_net) ||
satosat( &ro->ro_dst )->sat_addr.s_node != satosat(&ro->ro_dst)->sat_addr.s_node !=
sat->sat_addr.s_node )) { sat->sat_addr.s_node)) {
RTFREE( ro->ro_rt ); RTFREE(ro->ro_rt);
ro->ro_rt = NULL; ro->ro_rt = NULL;
} }
} }
@ -185,42 +185,42 @@ at_pcbconnect(struct ddpcb *ddp, struct sockaddr *addr, struct thread *td)
/* /*
* If we've got no route for this interface, try to find one. * If we've got no route for this interface, try to find one.
*/ */
if ( ro->ro_rt == NULL || ro->ro_rt->rt_ifp == NULL ) { if (ro->ro_rt == NULL || ro->ro_rt->rt_ifp == NULL) {
ro->ro_dst.sa_len = sizeof( struct sockaddr_at ); ro->ro_dst.sa_len = sizeof(struct sockaddr_at);
ro->ro_dst.sa_family = AF_APPLETALK; ro->ro_dst.sa_family = AF_APPLETALK;
if ( hintnet ) { if (hintnet) {
satosat( &ro->ro_dst )->sat_addr.s_net = hintnet; satosat(&ro->ro_dst)->sat_addr.s_net = hintnet;
} else { } else {
satosat( &ro->ro_dst )->sat_addr.s_net = sat->sat_addr.s_net; satosat(&ro->ro_dst)->sat_addr.s_net = sat->sat_addr.s_net;
} }
satosat( &ro->ro_dst )->sat_addr.s_node = sat->sat_addr.s_node; satosat(&ro->ro_dst)->sat_addr.s_node = sat->sat_addr.s_node;
rtalloc( ro ); rtalloc(ro);
} }
/* /*
* Make sure any route that we have has a valid interface. * Make sure any route that we have has a valid interface.
*/ */
aa = NULL; aa = NULL;
if ( ro->ro_rt && ( ifp = ro->ro_rt->rt_ifp )) { if (ro->ro_rt && (ifp = ro->ro_rt->rt_ifp)) {
for ( aa = at_ifaddr; aa; aa = aa->aa_next ) { for (aa = at_ifaddr; aa; aa = aa->aa_next) {
if ( aa->aa_ifp == ifp ) { if (aa->aa_ifp == ifp) {
break; break;
} }
} }
} }
if ( aa == NULL ) { if (aa == NULL) {
return( ENETUNREACH ); return (ENETUNREACH);
} }
ddp->ddp_fsat = *sat; ddp->ddp_fsat = *sat;
if ( ddp->ddp_lsat.sat_port == ATADDR_ANYPORT ) { if (ddp->ddp_lsat.sat_port == ATADDR_ANYPORT) {
return(at_pcbsetaddr(ddp, NULL, td)); return (at_pcbsetaddr(ddp, NULL, td));
} }
return( 0 ); return (0);
} }
void void
at_pcbdisconnect( struct ddpcb *ddp ) at_pcbdisconnect(struct ddpcb *ddp)
{ {
ddp->ddp_fsat.sat_addr.s_net = ATADDR_ANYNET; ddp->ddp_fsat.sat_addr.s_net = ATADDR_ANYNET;
ddp->ddp_fsat.sat_addr.s_node = ATADDR_ANYNODE; ddp->ddp_fsat.sat_addr.s_node = ATADDR_ANYNODE;
@ -228,7 +228,7 @@ at_pcbdisconnect( struct ddpcb *ddp )
} }
int int
at_pcballoc( struct socket *so ) at_pcballoc(struct socket *so)
{ {
struct ddpcb *ddp; struct ddpcb *ddp;
@ -246,39 +246,39 @@ at_pcballoc( struct socket *so )
ddp->ddp_socket = so; ddp->ddp_socket = so;
so->so_pcb = (caddr_t)ddp; so->so_pcb = (caddr_t)ddp;
return(0); return (0);
} }
void void
at_pcbdetach( struct socket *so, struct ddpcb *ddp) at_pcbdetach(struct socket *so, struct ddpcb *ddp)
{ {
soisdisconnected( so ); soisdisconnected(so);
so->so_pcb = NULL; so->so_pcb = NULL;
sotryfree(so); sotryfree(so);
/* remove ddp from ddp_ports list */ /* remove ddp from ddp_ports list */
if ( ddp->ddp_lsat.sat_port != ATADDR_ANYPORT && if (ddp->ddp_lsat.sat_port != ATADDR_ANYPORT &&
ddp_ports[ ddp->ddp_lsat.sat_port - 1 ] != NULL ) { ddp_ports[ ddp->ddp_lsat.sat_port - 1 ] != NULL) {
if ( ddp->ddp_pprev != NULL ) { if (ddp->ddp_pprev != NULL) {
ddp->ddp_pprev->ddp_pnext = ddp->ddp_pnext; ddp->ddp_pprev->ddp_pnext = ddp->ddp_pnext;
} else { } else {
ddp_ports[ ddp->ddp_lsat.sat_port - 1 ] = ddp->ddp_pnext; ddp_ports[ ddp->ddp_lsat.sat_port - 1 ] = ddp->ddp_pnext;
} }
if ( ddp->ddp_pnext != NULL ) { if (ddp->ddp_pnext != NULL) {
ddp->ddp_pnext->ddp_pprev = ddp->ddp_pprev; ddp->ddp_pnext->ddp_pprev = ddp->ddp_pprev;
} }
} }
if ( ddp->ddp_route.ro_rt ) { if (ddp->ddp_route.ro_rt) {
RTFREE( ddp->ddp_route.ro_rt ); RTFREE(ddp->ddp_route.ro_rt);
} }
if ( ddp->ddp_prev ) { if (ddp->ddp_prev) {
ddp->ddp_prev->ddp_next = ddp->ddp_next; ddp->ddp_prev->ddp_next = ddp->ddp_next;
} else { } else {
ddpcb = ddp->ddp_next; ddpcb = ddp->ddp_next;
} }
if ( ddp->ddp_next ) { if (ddp->ddp_next) {
ddp->ddp_next->ddp_prev = ddp->ddp_prev; ddp->ddp_next->ddp_prev = ddp->ddp_prev;
} }
FREE(ddp, M_PCB); FREE(ddp, M_PCB);
@ -291,7 +291,7 @@ at_pcbdetach( struct socket *so, struct ddpcb *ddp)
* sockets (pcbs). * sockets (pcbs).
*/ */
struct ddpcb * struct ddpcb *
ddp_search( struct sockaddr_at *from, struct sockaddr_at *to, ddp_search(struct sockaddr_at *from, struct sockaddr_at *to,
struct at_ifaddr *aa) struct at_ifaddr *aa)
{ {
struct ddpcb *ddp; struct ddpcb *ddp;
@ -299,39 +299,39 @@ ddp_search( struct sockaddr_at *from, struct sockaddr_at *to,
/* /*
* Check for bad ports. * Check for bad ports.
*/ */
if ( to->sat_port < ATPORT_FIRST || to->sat_port >= ATPORT_LAST ) { if (to->sat_port < ATPORT_FIRST || to->sat_port >= ATPORT_LAST) {
return( NULL ); return (NULL);
} }
/* /*
* Make sure the local address matches the sent address. What about * Make sure the local address matches the sent address. What about
* the interface? * the interface?
*/ */
for ( ddp = ddp_ports[ to->sat_port - 1 ]; ddp; ddp = ddp->ddp_pnext ) { for (ddp = ddp_ports[ to->sat_port - 1 ]; ddp; ddp = ddp->ddp_pnext) {
/* XXX should we handle 0.YY? */ /* XXX should we handle 0.YY? */
/* XXXX.YY to socket on destination interface */ /* XXXX.YY to socket on destination interface */
if ( to->sat_addr.s_net == ddp->ddp_lsat.sat_addr.s_net && if (to->sat_addr.s_net == ddp->ddp_lsat.sat_addr.s_net &&
to->sat_addr.s_node == ddp->ddp_lsat.sat_addr.s_node ) { to->sat_addr.s_node == ddp->ddp_lsat.sat_addr.s_node) {
break; break;
} }
/* 0.255 to socket on receiving interface */ /* 0.255 to socket on receiving interface */
if ( to->sat_addr.s_node == ATADDR_BCAST && ( to->sat_addr.s_net == 0 || if (to->sat_addr.s_node == ATADDR_BCAST && (to->sat_addr.s_net == 0 ||
to->sat_addr.s_net == ddp->ddp_lsat.sat_addr.s_net ) && to->sat_addr.s_net == ddp->ddp_lsat.sat_addr.s_net) &&
ddp->ddp_lsat.sat_addr.s_net == AA_SAT( aa )->sat_addr.s_net ) { ddp->ddp_lsat.sat_addr.s_net == AA_SAT(aa)->sat_addr.s_net) {
break; break;
} }
/* XXXX.0 to socket on destination interface */ /* XXXX.0 to socket on destination interface */
if ( to->sat_addr.s_net == aa->aa_firstnet && if (to->sat_addr.s_net == aa->aa_firstnet &&
to->sat_addr.s_node == 0 && to->sat_addr.s_node == 0 &&
ntohs( ddp->ddp_lsat.sat_addr.s_net ) >= ntohs(ddp->ddp_lsat.sat_addr.s_net) >=
ntohs( aa->aa_firstnet ) && ntohs(aa->aa_firstnet) &&
ntohs( ddp->ddp_lsat.sat_addr.s_net ) <= ntohs(ddp->ddp_lsat.sat_addr.s_net) <=
ntohs( aa->aa_lastnet )) { ntohs(aa->aa_lastnet)) {
break; break;
} }
} }
return( ddp ); return (ddp);
} }

View file

@ -23,7 +23,7 @@
#include <netatalk/at_extern.h> #include <netatalk/at_extern.h>
static u_long ddp_sendspace = DDP_MAXSZ; /* Max ddp size + 1 (ddp_type) */ static u_long ddp_sendspace = DDP_MAXSZ; /* Max ddp size + 1 (ddp_type) */
static u_long ddp_recvspace = 10 * ( 587 + sizeof( struct sockaddr_at )); static u_long ddp_recvspace = 10 * (587 + sizeof(struct sockaddr_at));
static struct ifqueue atintrq1, atintrq2, aarpintrq; static struct ifqueue atintrq1, atintrq2, aarpintrq;
@ -35,18 +35,18 @@ ddp_attach(struct socket *so, int proto, struct thread *td)
int s; int s;
ddp = sotoddpcb( so ); ddp = sotoddpcb(so);
if ( ddp != NULL ) { if (ddp != NULL) {
return( EINVAL); return (EINVAL);
} }
s = splnet(); s = splnet();
error = at_pcballoc( so ); error = at_pcballoc(so);
splx(s); splx(s);
if (error) { if (error) {
return (error); return (error);
} }
return (soreserve( so, ddp_sendspace, ddp_recvspace )); return (soreserve(so, ddp_sendspace, ddp_recvspace));
} }
static int static int
@ -55,14 +55,14 @@ ddp_detach(struct socket *so)
struct ddpcb *ddp; struct ddpcb *ddp;
int s; int s;
ddp = sotoddpcb( so ); ddp = sotoddpcb(so);
if ( ddp == NULL ) { if (ddp == NULL) {
return( EINVAL); return (EINVAL);
} }
s = splnet(); s = splnet();
at_pcbdetach( so, ddp ); at_pcbdetach(so, ddp);
splx(s); splx(s);
return(0); return (0);
} }
static int static int
@ -72,9 +72,9 @@ ddp_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
int error = 0; int error = 0;
int s; int s;
ddp = sotoddpcb( so ); ddp = sotoddpcb(so);
if ( ddp == NULL ) { if (ddp == NULL) {
return( EINVAL); return (EINVAL);
} }
s = splnet(); s = splnet();
error = at_pcbsetaddr(ddp, nam, td); error = at_pcbsetaddr(ddp, nam, td);
@ -89,21 +89,21 @@ ddp_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
int error = 0; int error = 0;
int s; int s;
ddp = sotoddpcb( so ); ddp = sotoddpcb(so);
if ( ddp == NULL ) { if (ddp == NULL) {
return( EINVAL); return (EINVAL);
} }
if ( ddp->ddp_fsat.sat_port != ATADDR_ANYPORT ) { if (ddp->ddp_fsat.sat_port != ATADDR_ANYPORT) {
return(EISCONN); return (EISCONN);
} }
s = splnet(); s = splnet();
error = at_pcbconnect( ddp, nam, td ); error = at_pcbconnect(ddp, nam, td);
splx(s); splx(s);
if ( error == 0 ) if (error == 0)
soisconnected( so ); soisconnected(so);
return(error); return (error);
} }
static int static int
@ -113,20 +113,20 @@ ddp_disconnect(struct socket *so)
struct ddpcb *ddp; struct ddpcb *ddp;
int s; int s;
ddp = sotoddpcb( so ); ddp = sotoddpcb(so);
if ( ddp == NULL ) { if (ddp == NULL) {
return( EINVAL); return (EINVAL);
} }
if ( ddp->ddp_fsat.sat_addr.s_node == ATADDR_ANYNODE ) { if (ddp->ddp_fsat.sat_addr.s_node == ATADDR_ANYNODE) {
return(ENOTCONN); return (ENOTCONN);
} }
s = splnet(); s = splnet();
at_pcbdisconnect( ddp ); at_pcbdisconnect(ddp);
ddp->ddp_fsat.sat_addr.s_node = ATADDR_ANYNODE; ddp->ddp_fsat.sat_addr.s_node = ATADDR_ANYNODE;
splx(s); splx(s);
soisdisconnected( so ); soisdisconnected(so);
return(0); return (0);
} }
static int static int
@ -134,12 +134,12 @@ ddp_shutdown(struct socket *so)
{ {
struct ddpcb *ddp; struct ddpcb *ddp;
ddp = sotoddpcb( so ); ddp = sotoddpcb(so);
if ( ddp == NULL ) { if (ddp == NULL) {
return( EINVAL); return (EINVAL);
} }
socantsendmore( so ); socantsendmore(so);
return(0); return (0);
} }
static int static int
@ -150,39 +150,39 @@ ddp_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
int error = 0; int error = 0;
int s; int s;
ddp = sotoddpcb( so ); ddp = sotoddpcb(so);
if ( ddp == NULL ) { if (ddp == NULL) {
return(EINVAL); return (EINVAL);
} }
if ( control && control->m_len ) { if (control && control->m_len) {
return(EINVAL); return (EINVAL);
} }
if ( addr ) { if (addr) {
if ( ddp->ddp_fsat.sat_port != ATADDR_ANYPORT ) { if (ddp->ddp_fsat.sat_port != ATADDR_ANYPORT) {
return(EISCONN); return (EISCONN);
} }
s = splnet(); s = splnet();
error = at_pcbconnect(ddp, addr, td); error = at_pcbconnect(ddp, addr, td);
splx( s ); splx(s);
if ( error ) { if (error) {
return(error); return (error);
} }
} else { } else {
if ( ddp->ddp_fsat.sat_port == ATADDR_ANYPORT ) { if (ddp->ddp_fsat.sat_port == ATADDR_ANYPORT) {
return(ENOTCONN); return (ENOTCONN);
} }
} }
s = splnet(); s = splnet();
error = ddp_output( m, so ); error = ddp_output(m, so);
if ( addr ) { if (addr) {
at_pcbdisconnect( ddp ); at_pcbdisconnect(ddp);
} }
splx(s); splx(s);
return(error); return (error);
} }
static int static int
@ -191,15 +191,15 @@ ddp_abort(struct socket *so)
struct ddpcb *ddp; struct ddpcb *ddp;
int s; int s;
ddp = sotoddpcb( so ); ddp = sotoddpcb(so);
if ( ddp == NULL ) { if (ddp == NULL) {
return(EINVAL); return (EINVAL);
} }
soisdisconnected( so ); soisdisconnected(so);
s = splnet(); s = splnet();
at_pcbdetach( so, ddp ); at_pcbdetach(so, ddp);
splx(s); splx(s);
return(0); return (0);
} }
void void
@ -219,12 +219,12 @@ ddp_init(void)
#if 0 #if 0
static void static void
ddp_clean(void ) ddp_clean(void)
{ {
struct ddpcb *ddp; struct ddpcb *ddp;
for ( ddp = ddpcb; ddp; ddp = ddp->ddp_next ) { for (ddp = ddpcb; ddp; ddp = ddp->ddp_next) {
at_pcbdetach( ddp->ddp_socket, ddp ); at_pcbdetach(ddp->ddp_socket, ddp);
} }
} }
#endif #endif
@ -232,7 +232,7 @@ ddp_clean(void )
static int static int
at_setpeeraddr(struct socket *so, struct sockaddr **nam) at_setpeeraddr(struct socket *so, struct sockaddr **nam)
{ {
return(EOPNOTSUPP); return (EOPNOTSUPP);
} }
static int static int
@ -240,12 +240,12 @@ at_setsockaddr(struct socket *so, struct sockaddr **nam)
{ {
struct ddpcb *ddp; struct ddpcb *ddp;
ddp = sotoddpcb( so ); ddp = sotoddpcb(so);
if ( ddp == NULL ) { if (ddp == NULL) {
return( EINVAL); return (EINVAL);
} }
at_sockaddr( ddp, nam ); at_sockaddr(ddp, nam);
return(0); return (0);
} }
struct pr_usrreqs ddp_usrreqs = { struct pr_usrreqs ddp_usrreqs = {