aarp.c (194619) | aarp.c (194819) |
---|---|
1/*- 2 * Copyright (c) 2004-2009 Robert N. M. Watson 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 33 unchanged lines hidden (view full) --- 42 * Research Systems Unix Group 43 * The University of Michigan 44 * c/o Wesley Craig 45 * 535 W. William Street 46 * Ann Arbor, Michigan 47 * +1-313-764-2278 48 * netatalk@umich.edu 49 * | 1/*- 2 * Copyright (c) 2004-2009 Robert N. M. Watson 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 33 unchanged lines hidden (view full) --- 42 * Research Systems Unix Group 43 * The University of Michigan 44 * c/o Wesley Craig 45 * 535 W. William Street 46 * Ann Arbor, Michigan 47 * +1-313-764-2278 48 * netatalk@umich.edu 49 * |
50 * $FreeBSD: head/sys/netatalk/aarp.c 194619 2009-06-22 10:23:54Z rwatson $ | 50 * $FreeBSD: head/sys/netatalk/aarp.c 194819 2009-06-24 10:32:44Z rwatson $ |
51 */ 52 53#include "opt_atalk.h" 54 55#include <sys/param.h> 56#include <sys/systm.h> 57#include <sys/mbuf.h> 58#include <sys/kernel.h> --- 78 unchanged lines hidden (view full) --- 137 aarptfree(aat); 138 } 139 AARPTAB_UNLOCK(); 140} 141 142/* 143 * Search through the network addresses to find one that includes the given 144 * network. Remember to take netranges into consideration. | 51 */ 52 53#include "opt_atalk.h" 54 55#include <sys/param.h> 56#include <sys/systm.h> 57#include <sys/mbuf.h> 58#include <sys/kernel.h> --- 78 unchanged lines hidden (view full) --- 137 aarptfree(aat); 138 } 139 AARPTAB_UNLOCK(); 140} 141 142/* 143 * Search through the network addresses to find one that includes the given 144 * network. Remember to take netranges into consideration. |
145 * 146 * The _locked variant relies on the caller holding the at_ifaddr lock; the 147 * unlocked variant returns a reference that the caller must dispose of. |
|
145 */ 146struct at_ifaddr * | 148 */ 149struct at_ifaddr * |
147at_ifawithnet(struct sockaddr_at *sat) | 150at_ifawithnet_locked(struct sockaddr_at *sat) |
148{ 149 struct at_ifaddr *aa; 150 struct sockaddr_at *sat2; 151 152 AT_IFADDR_LOCK_ASSERT(); 153 154 for (aa = at_ifaddr_list; aa != NULL; aa = aa->aa_next) { 155 sat2 = &(aa->aa_addr); 156 if (sat2->sat_addr.s_net == sat->sat_addr.s_net) 157 break; 158 if ((aa->aa_flags & AFA_PHASE2) && 159 (ntohs(aa->aa_firstnet) <= ntohs(sat->sat_addr.s_net)) && 160 (ntohs(aa->aa_lastnet) >= ntohs(sat->sat_addr.s_net))) 161 break; 162 } 163 return (aa); 164} 165 | 151{ 152 struct at_ifaddr *aa; 153 struct sockaddr_at *sat2; 154 155 AT_IFADDR_LOCK_ASSERT(); 156 157 for (aa = at_ifaddr_list; aa != NULL; aa = aa->aa_next) { 158 sat2 = &(aa->aa_addr); 159 if (sat2->sat_addr.s_net == sat->sat_addr.s_net) 160 break; 161 if ((aa->aa_flags & AFA_PHASE2) && 162 (ntohs(aa->aa_firstnet) <= ntohs(sat->sat_addr.s_net)) && 163 (ntohs(aa->aa_lastnet) >= ntohs(sat->sat_addr.s_net))) 164 break; 165 } 166 return (aa); 167} 168 |
169struct at_ifaddr * 170at_ifawithnet(struct sockaddr_at *sat) 171{ 172 struct at_ifaddr *aa; 173 174 AT_IFADDR_RLOCK(); 175 aa = at_ifawithnet_locked(sat); 176 if (aa != NULL) 177 ifa_ref(&aa->aa_ifa); 178 AT_IFADDR_RUNLOCK(); 179 return (aa); 180} 181 |
|
166static void 167aarpwhohas(struct ifnet *ifp, struct sockaddr_at *sat) 168{ 169 struct mbuf *m; 170 struct ether_header *eh; 171 struct ether_aarp *ea; 172 struct at_ifaddr *aa; 173 struct llc *llc; --- 22 unchanged lines hidden (view full) --- 196 197 /* 198 * We need to check whether the output ethernet type should be phase 199 * 1 or 2. We have the interface that we'll be sending the aarp out. 200 * We need to find an AppleTalk network on that interface with the 201 * same address as we're looking for. If the net is phase 2, 202 * generate an 802.2 and SNAP header. 203 */ | 182static void 183aarpwhohas(struct ifnet *ifp, struct sockaddr_at *sat) 184{ 185 struct mbuf *m; 186 struct ether_header *eh; 187 struct ether_aarp *ea; 188 struct at_ifaddr *aa; 189 struct llc *llc; --- 22 unchanged lines hidden (view full) --- 212 213 /* 214 * We need to check whether the output ethernet type should be phase 215 * 1 or 2. We have the interface that we'll be sending the aarp out. 216 * We need to find an AppleTalk network on that interface with the 217 * same address as we're looking for. If the net is phase 2, 218 * generate an 802.2 and SNAP header. 219 */ |
204 AT_IFADDR_RLOCK(); 205 if ((aa = at_ifawithnet(sat)) == NULL) { 206 AT_IFADDR_RUNLOCK(); | 220 aa = at_ifawithnet(sat); 221 if (aa == NULL) { |
207 m_freem(m); 208 return; 209 } 210 211 eh = (struct ether_header *)sa.sa_data; 212 213 if (aa->aa_flags & AFA_PHASE2) { 214 bcopy(atmulticastaddr, eh->ether_dhost, 215 sizeof(eh->ether_dhost)); 216 eh->ether_type = htons(sizeof(struct llc) + 217 sizeof(struct ether_aarp)); 218 M_PREPEND(m, sizeof(struct llc), M_DONTWAIT); 219 if (m == NULL) { | 222 m_freem(m); 223 return; 224 } 225 226 eh = (struct ether_header *)sa.sa_data; 227 228 if (aa->aa_flags & AFA_PHASE2) { 229 bcopy(atmulticastaddr, eh->ether_dhost, 230 sizeof(eh->ether_dhost)); 231 eh->ether_type = htons(sizeof(struct llc) + 232 sizeof(struct ether_aarp)); 233 M_PREPEND(m, sizeof(struct llc), M_DONTWAIT); 234 if (m == NULL) { |
220 AT_IFADDR_RUNLOCK(); | 235 ifa_free(&aa->aa_ifa); |
221 return; 222 } 223 llc = mtod(m, struct llc *); 224 llc->llc_dsap = llc->llc_ssap = LLC_SNAP_LSAP; 225 llc->llc_control = LLC_UI; 226 bcopy(aarp_org_code, llc->llc_org_code, 227 sizeof(aarp_org_code)); 228 llc->llc_ether_type = htons(ETHERTYPE_AARP); --- 10 unchanged lines hidden (view full) --- 239 ea->aarp_spa = AA_SAT(aa)->sat_addr.s_node; 240 ea->aarp_tpa = sat->sat_addr.s_node; 241 } 242 243#ifdef NETATALKDEBUG 244 printf("aarp: sending request for %u.%u\n", 245 ntohs(AA_SAT(aa)->sat_addr.s_net), AA_SAT(aa)->sat_addr.s_node); 246#endif /* NETATALKDEBUG */ | 236 return; 237 } 238 llc = mtod(m, struct llc *); 239 llc->llc_dsap = llc->llc_ssap = LLC_SNAP_LSAP; 240 llc->llc_control = LLC_UI; 241 bcopy(aarp_org_code, llc->llc_org_code, 242 sizeof(aarp_org_code)); 243 llc->llc_ether_type = htons(ETHERTYPE_AARP); --- 10 unchanged lines hidden (view full) --- 254 ea->aarp_spa = AA_SAT(aa)->sat_addr.s_node; 255 ea->aarp_tpa = sat->sat_addr.s_node; 256 } 257 258#ifdef NETATALKDEBUG 259 printf("aarp: sending request for %u.%u\n", 260 ntohs(AA_SAT(aa)->sat_addr.s_net), AA_SAT(aa)->sat_addr.s_node); 261#endif /* NETATALKDEBUG */ |
247 AT_IFADDR_RUNLOCK(); | 262 ifa_free(&aa->aa_ifa); |
248 249 sa.sa_len = sizeof(struct sockaddr); 250 sa.sa_family = AF_UNSPEC; 251 ifp->if_output(ifp, m, &sa, NULL); 252} 253 254int 255aarpresolve(struct ifnet *ifp, struct mbuf *m, struct sockaddr_at *destsat, 256 u_char *desten) 257{ 258 struct at_ifaddr *aa; 259 struct aarptab *aat; 260 261 AT_IFADDR_RLOCK(); 262 if (at_broadcast(destsat)) { 263 m->m_flags |= M_BCAST; | 263 264 sa.sa_len = sizeof(struct sockaddr); 265 sa.sa_family = AF_UNSPEC; 266 ifp->if_output(ifp, m, &sa, NULL); 267} 268 269int 270aarpresolve(struct ifnet *ifp, struct mbuf *m, struct sockaddr_at *destsat, 271 u_char *desten) 272{ 273 struct at_ifaddr *aa; 274 struct aarptab *aat; 275 276 AT_IFADDR_RLOCK(); 277 if (at_broadcast(destsat)) { 278 m->m_flags |= M_BCAST; |
264 if ((aa = at_ifawithnet(destsat)) == NULL) { | 279 if ((aa = at_ifawithnet_locked(destsat)) == NULL) { |
265 AT_IFADDR_RUNLOCK(); 266 m_freem(m); 267 return (0); 268 } 269 if (aa->aa_flags & AFA_PHASE2) 270 bcopy(atmulticastaddr, (caddr_t)desten, 271 sizeof(atmulticastaddr)); 272 else --- 101 unchanged lines hidden (view full) --- 374 op = ntohs(ea->aarp_op); 375 bcopy(ea->aarp_tpnet, &net, sizeof(net)); 376 377 if (net != 0) { 378 /* Should be ATADDR_ANYNET? */ 379 sat.sat_len = sizeof(struct sockaddr_at); 380 sat.sat_family = AF_APPLETALK; 381 sat.sat_addr.s_net = net; | 280 AT_IFADDR_RUNLOCK(); 281 m_freem(m); 282 return (0); 283 } 284 if (aa->aa_flags & AFA_PHASE2) 285 bcopy(atmulticastaddr, (caddr_t)desten, 286 sizeof(atmulticastaddr)); 287 else --- 101 unchanged lines hidden (view full) --- 389 op = ntohs(ea->aarp_op); 390 bcopy(ea->aarp_tpnet, &net, sizeof(net)); 391 392 if (net != 0) { 393 /* Should be ATADDR_ANYNET? */ 394 sat.sat_len = sizeof(struct sockaddr_at); 395 sat.sat_family = AF_APPLETALK; 396 sat.sat_addr.s_net = net; |
382 AT_IFADDR_RLOCK(); 383 if ((aa = at_ifawithnet(&sat)) == NULL) { 384 AT_IFADDR_RUNLOCK(); | 397 aa = at_ifawithnet(&sat); 398 if (aa == NULL) { |
385 m_freem(m); 386 return; 387 } | 399 m_freem(m); 400 return; 401 } |
388 ifa_ref(&aa->aa_ifa); 389 AT_IFADDR_RUNLOCK(); | |
390 bcopy(ea->aarp_spnet, &spa.s_net, sizeof(spa.s_net)); 391 bcopy(ea->aarp_tpnet, &tpa.s_net, sizeof(tpa.s_net)); 392 } else { 393 /* 394 * Since we don't know the net, we just look for the first 395 * phase 1 address on the interface. 396 */ 397 IF_ADDR_LOCK(ifp); --- 315 unchanged lines hidden --- | 402 bcopy(ea->aarp_spnet, &spa.s_net, sizeof(spa.s_net)); 403 bcopy(ea->aarp_tpnet, &tpa.s_net, sizeof(tpa.s_net)); 404 } else { 405 /* 406 * Since we don't know the net, we just look for the first 407 * phase 1 address on the interface. 408 */ 409 IF_ADDR_LOCK(ifp); --- 315 unchanged lines hidden --- |