if.c (62b119cabdc7e33d8a93d107880cc75aa77eff18) | if.c (22f29826756b763aca9e89b47514fc327289cd8e) |
---|---|
1/* 2 * Copyright (c) 1980, 1986, 1993 3 * The Regents of the University of California. 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 --- 96 unchanged lines hidden (view full) --- 105void 106ifinit(dummy) 107 void *dummy; 108{ 109 struct ifnet *ifp; 110 int s; 111 112 s = splimp(); | 1/* 2 * Copyright (c) 1980, 1986, 1993 3 * The Regents of the University of California. 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 --- 96 unchanged lines hidden (view full) --- 105void 106ifinit(dummy) 107 void *dummy; 108{ 109 struct ifnet *ifp; 110 int s; 111 112 s = splimp(); |
113 for (ifp = ifnet.tqh_first; ifp; ifp = ifp->if_link.tqe_next) { | 113 for (ifp = TAILQ_FIRST(&ifnet); ifp; ifp = TAILQ_NEXT(ifp, if_link)) { |
114 if (ifp->if_snd.ifq_maxlen == 0) { 115 printf("%s%d XXX: driver didn't set ifq_maxlen\n", 116 ifp->if_name, ifp->if_unit); 117 ifp->if_snd.ifq_maxlen = ifqmaxlen; 118 } 119 /* XXX This is an access violation of the mutex internals. */ 120 if (ifp->if_snd.ifq_mtx.mtx_description == NULL) { 121 printf("%s%d XXX: driver didn't initialize queue mtx\n", --- 230 unchanged lines hidden (view full) --- 352ifa_ifwithaddr(addr) 353 register struct sockaddr *addr; 354{ 355 register struct ifnet *ifp; 356 register struct ifaddr *ifa; 357 358#define equal(a1, a2) \ 359 (bcmp((caddr_t)(a1), (caddr_t)(a2), ((struct sockaddr *)(a1))->sa_len) == 0) | 114 if (ifp->if_snd.ifq_maxlen == 0) { 115 printf("%s%d XXX: driver didn't set ifq_maxlen\n", 116 ifp->if_name, ifp->if_unit); 117 ifp->if_snd.ifq_maxlen = ifqmaxlen; 118 } 119 /* XXX This is an access violation of the mutex internals. */ 120 if (ifp->if_snd.ifq_mtx.mtx_description == NULL) { 121 printf("%s%d XXX: driver didn't initialize queue mtx\n", --- 230 unchanged lines hidden (view full) --- 352ifa_ifwithaddr(addr) 353 register struct sockaddr *addr; 354{ 355 register struct ifnet *ifp; 356 register struct ifaddr *ifa; 357 358#define equal(a1, a2) \ 359 (bcmp((caddr_t)(a1), (caddr_t)(a2), ((struct sockaddr *)(a1))->sa_len) == 0) |
360 for (ifp = ifnet.tqh_first; ifp; ifp = ifp->if_link.tqe_next) 361 for (ifa = ifp->if_addrhead.tqh_first; ifa; 362 ifa = ifa->ifa_link.tqe_next) { | 360 for (ifp = TAILQ_FIRST(&ifnet); ifp; ifp = TAILQ_NEXT(ifp, if_link)) 361 for (ifa = TAILQ_FIRST(&ifp->if_addrhead); ifa; 362 ifa = TAILQ_NEXT(ifa, ifa_link)) { |
363 if (ifa->ifa_addr->sa_family != addr->sa_family) 364 continue; 365 if (equal(addr, ifa->ifa_addr)) 366 return (ifa); 367 if ((ifp->if_flags & IFF_BROADCAST) && ifa->ifa_broadaddr && 368 /* IP6 doesn't have broadcast */ 369 ifa->ifa_broadaddr->sa_len != 0 && 370 equal(ifa->ifa_broadaddr, addr)) --- 7 unchanged lines hidden (view full) --- 378/*ARGSUSED*/ 379struct ifaddr * 380ifa_ifwithdstaddr(addr) 381 register struct sockaddr *addr; 382{ 383 register struct ifnet *ifp; 384 register struct ifaddr *ifa; 385 | 363 if (ifa->ifa_addr->sa_family != addr->sa_family) 364 continue; 365 if (equal(addr, ifa->ifa_addr)) 366 return (ifa); 367 if ((ifp->if_flags & IFF_BROADCAST) && ifa->ifa_broadaddr && 368 /* IP6 doesn't have broadcast */ 369 ifa->ifa_broadaddr->sa_len != 0 && 370 equal(ifa->ifa_broadaddr, addr)) --- 7 unchanged lines hidden (view full) --- 378/*ARGSUSED*/ 379struct ifaddr * 380ifa_ifwithdstaddr(addr) 381 register struct sockaddr *addr; 382{ 383 register struct ifnet *ifp; 384 register struct ifaddr *ifa; 385 |
386 for (ifp = ifnet.tqh_first; ifp; ifp = ifp->if_link.tqe_next) | 386 for (ifp = TAILQ_FIRST(&ifnet); ifp; ifp = TAILQ_NEXT(ifp, if_link)) |
387 if (ifp->if_flags & IFF_POINTOPOINT) | 387 if (ifp->if_flags & IFF_POINTOPOINT) |
388 for (ifa = ifp->if_addrhead.tqh_first; ifa; 389 ifa = ifa->ifa_link.tqe_next) { | 388 for (ifa = TAILQ_FIRST(&ifp->if_addrhead); ifa; 389 ifa = TAILQ_NEXT(ifa, ifa_link)) { |
390 if (ifa->ifa_addr->sa_family != addr->sa_family) 391 continue; 392 if (ifa->ifa_dstaddr && equal(addr, ifa->ifa_dstaddr)) 393 return (ifa); 394 } 395 return ((struct ifaddr *)0); 396} 397 --- 20 unchanged lines hidden (view full) --- 418 if (sdl->sdl_index && sdl->sdl_index <= if_index) 419 return (ifnet_addrs[sdl->sdl_index - 1]); 420 } 421 422 /* 423 * Scan though each interface, looking for ones that have 424 * addresses in this address family. 425 */ | 390 if (ifa->ifa_addr->sa_family != addr->sa_family) 391 continue; 392 if (ifa->ifa_dstaddr && equal(addr, ifa->ifa_dstaddr)) 393 return (ifa); 394 } 395 return ((struct ifaddr *)0); 396} 397 --- 20 unchanged lines hidden (view full) --- 418 if (sdl->sdl_index && sdl->sdl_index <= if_index) 419 return (ifnet_addrs[sdl->sdl_index - 1]); 420 } 421 422 /* 423 * Scan though each interface, looking for ones that have 424 * addresses in this address family. 425 */ |
426 for (ifp = ifnet.tqh_first; ifp; ifp = ifp->if_link.tqe_next) { 427 for (ifa = ifp->if_addrhead.tqh_first; ifa; 428 ifa = ifa->ifa_link.tqe_next) { | 426 for (ifp = TAILQ_FIRST(&ifnet); ifp; ifp = TAILQ_NEXT(ifp, if_link)) { 427 for (ifa = TAILQ_FIRST(&ifp->if_addrhead); ifa; 428 ifa = TAILQ_NEXT(ifa, ifa_link)) { |
429 register char *cp, *cp2, *cp3; 430 431 if (ifa->ifa_addr->sa_family != af) 432next: continue; 433 if ( 434#ifdef INET6 /* XXX: for maching gif tunnel dst as routing entry gateway */ 435 addr->sa_family != AF_INET6 && 436#endif --- 68 unchanged lines hidden (view full) --- 505 register struct ifaddr *ifa; 506 register char *cp, *cp2, *cp3; 507 register char *cplim; 508 struct ifaddr *ifa_maybe = 0; 509 u_int af = addr->sa_family; 510 511 if (af >= AF_MAX) 512 return (0); | 429 register char *cp, *cp2, *cp3; 430 431 if (ifa->ifa_addr->sa_family != af) 432next: continue; 433 if ( 434#ifdef INET6 /* XXX: for maching gif tunnel dst as routing entry gateway */ 435 addr->sa_family != AF_INET6 && 436#endif --- 68 unchanged lines hidden (view full) --- 505 register struct ifaddr *ifa; 506 register char *cp, *cp2, *cp3; 507 register char *cplim; 508 struct ifaddr *ifa_maybe = 0; 509 u_int af = addr->sa_family; 510 511 if (af >= AF_MAX) 512 return (0); |
513 for (ifa = ifp->if_addrhead.tqh_first; ifa; 514 ifa = ifa->ifa_link.tqe_next) { | 513 for (ifa = TAILQ_FIRST(&ifp->if_addrhead); ifa; 514 ifa = TAILQ_NEXT(ifa, ifa_link)) { |
515 if (ifa->ifa_addr->sa_family != af) 516 continue; 517 if (ifa_maybe == 0) 518 ifa_maybe = ifa; 519 if (ifa->ifa_netmask == 0) { 520 if (equal(addr, ifa->ifa_addr) || 521 (ifa->ifa_dstaddr && equal(addr, ifa->ifa_dstaddr))) 522 return (ifa); --- 143 unchanged lines hidden (view full) --- 666 */ 667static void 668if_slowtimo(arg) 669 void *arg; 670{ 671 register struct ifnet *ifp; 672 int s = splimp(); 673 | 515 if (ifa->ifa_addr->sa_family != af) 516 continue; 517 if (ifa_maybe == 0) 518 ifa_maybe = ifa; 519 if (ifa->ifa_netmask == 0) { 520 if (equal(addr, ifa->ifa_addr) || 521 (ifa->ifa_dstaddr && equal(addr, ifa->ifa_dstaddr))) 522 return (ifa); --- 143 unchanged lines hidden (view full) --- 666 */ 667static void 668if_slowtimo(arg) 669 void *arg; 670{ 671 register struct ifnet *ifp; 672 int s = splimp(); 673 |
674 for (ifp = ifnet.tqh_first; ifp; ifp = ifp->if_link.tqe_next) { | 674 for (ifp = TAILQ_FIRST(&ifnet); ifp; ifp = TAILQ_NEXT(ifp, if_link)) { |
675 if (ifp->if_timer == 0 || --ifp->if_timer) 676 continue; 677 if (ifp->if_watchdog) 678 (*ifp->if_watchdog)(ifp); 679 } 680 splx(s); 681 timeout(if_slowtimo, (void *)0, hz / IFNET_SLOWHZ); 682} --- 31 unchanged lines hidden (view full) --- 714 c = *--cp; 715 } while (c >= '0' && c <= '9'); 716 len = cp - name + 1; 717 bcopy(name, namebuf, len); 718 namebuf[len] = '\0'; 719 /* 720 * Now search all the interfaces for this name/number 721 */ | 675 if (ifp->if_timer == 0 || --ifp->if_timer) 676 continue; 677 if (ifp->if_watchdog) 678 (*ifp->if_watchdog)(ifp); 679 } 680 splx(s); 681 timeout(if_slowtimo, (void *)0, hz / IFNET_SLOWHZ); 682} --- 31 unchanged lines hidden (view full) --- 714 c = *--cp; 715 } while (c >= '0' && c <= '9'); 716 len = cp - name + 1; 717 bcopy(name, namebuf, len); 718 namebuf[len] = '\0'; 719 /* 720 * Now search all the interfaces for this name/number 721 */ |
722 for (ifp = ifnet.tqh_first; ifp; ifp = ifp->if_link.tqe_next) { | 722 for (ifp = TAILQ_FIRST(&ifnet); ifp; ifp = TAILQ_NEXT(ifp, if_link)) { |
723 if (strcmp(ifp->if_name, namebuf)) 724 continue; 725 if (unit == ifp->if_unit) 726 break; 727 } 728 return (ifp); 729} 730 --- 324 unchanged lines hidden (view full) --- 1055 */ 1056/*ARGSUSED*/ 1057static int 1058ifconf(cmd, data) 1059 u_long cmd; 1060 caddr_t data; 1061{ 1062 register struct ifconf *ifc = (struct ifconf *)data; | 723 if (strcmp(ifp->if_name, namebuf)) 724 continue; 725 if (unit == ifp->if_unit) 726 break; 727 } 728 return (ifp); 729} 730 --- 324 unchanged lines hidden (view full) --- 1055 */ 1056/*ARGSUSED*/ 1057static int 1058ifconf(cmd, data) 1059 u_long cmd; 1060 caddr_t data; 1061{ 1062 register struct ifconf *ifc = (struct ifconf *)data; |
1063 register struct ifnet *ifp = ifnet.tqh_first; | 1063 register struct ifnet *ifp = TAILQ_FIRST(&ifnet); |
1064 register struct ifaddr *ifa; 1065 struct ifreq ifr, *ifrp; 1066 int space = ifc->ifc_len, error = 0; 1067 1068 ifrp = ifc->ifc_req; | 1064 register struct ifaddr *ifa; 1065 struct ifreq ifr, *ifrp; 1066 int space = ifc->ifc_len, error = 0; 1067 1068 ifrp = ifc->ifc_req; |
1069 for (; space > sizeof (ifr) && ifp; ifp = ifp->if_link.tqe_next) { | 1069 for (; space > sizeof (ifr) && ifp; ifp = TAILQ_NEXT(ifp, if_link)) { |
1070 char workbuf[64]; 1071 int ifnlen, addrs; 1072 1073 ifnlen = snprintf(workbuf, sizeof(workbuf), 1074 "%s%d", ifp->if_name, ifp->if_unit); 1075 if(ifnlen + 1 > sizeof ifr.ifr_name) { 1076 error = ENAMETOOLONG; 1077 break; 1078 } else { 1079 strcpy(ifr.ifr_name, workbuf); 1080 } 1081 1082 addrs = 0; | 1070 char workbuf[64]; 1071 int ifnlen, addrs; 1072 1073 ifnlen = snprintf(workbuf, sizeof(workbuf), 1074 "%s%d", ifp->if_name, ifp->if_unit); 1075 if(ifnlen + 1 > sizeof ifr.ifr_name) { 1076 error = ENAMETOOLONG; 1077 break; 1078 } else { 1079 strcpy(ifr.ifr_name, workbuf); 1080 } 1081 1082 addrs = 0; |
1083 ifa = ifp->if_addrhead.tqh_first; | 1083 ifa = TAILQ_FIRST(&ifp->if_addrhead); |
1084 for ( ; space > sizeof (ifr) && ifa; | 1084 for ( ; space > sizeof (ifr) && ifa; |
1085 ifa = ifa->ifa_link.tqe_next) { | 1085 ifa = TAILQ_NEXT(ifa, ifa_link)) { |
1086 register struct sockaddr *sa = ifa->ifa_addr; 1087 if (curproc->p_prison && prison_if(curproc, sa)) 1088 continue; 1089 addrs++; 1090#ifdef COMPAT_43 1091 if (cmd == OSIOCGIFCONF) { 1092 struct osockaddr *osa = 1093 (struct osockaddr *)&ifr.ifr_addr; --- 87 unchanged lines hidden (view full) --- 1181 struct sockaddr *llsa, *dupsa; 1182 int error, s; 1183 struct ifmultiaddr *ifma; 1184 1185 /* 1186 * If the matching multicast address already exists 1187 * then don't add a new one, just add a reference 1188 */ | 1086 register struct sockaddr *sa = ifa->ifa_addr; 1087 if (curproc->p_prison && prison_if(curproc, sa)) 1088 continue; 1089 addrs++; 1090#ifdef COMPAT_43 1091 if (cmd == OSIOCGIFCONF) { 1092 struct osockaddr *osa = 1093 (struct osockaddr *)&ifr.ifr_addr; --- 87 unchanged lines hidden (view full) --- 1181 struct sockaddr *llsa, *dupsa; 1182 int error, s; 1183 struct ifmultiaddr *ifma; 1184 1185 /* 1186 * If the matching multicast address already exists 1187 * then don't add a new one, just add a reference 1188 */ |
1189 for (ifma = ifp->if_multiaddrs.lh_first; ifma; 1190 ifma = ifma->ifma_link.le_next) { | 1189 for (ifma = LIST_FIRST(&ifp->if_multiaddrs); ifma; 1190 ifma = LIST_NEXT(ifma, ifma_link)) { |
1191 if (equal(sa, ifma->ifma_addr)) { 1192 ifma->ifma_refcount++; 1193 if (retifma) 1194 *retifma = ifma; 1195 return 0; 1196 } 1197 } 1198 --- 25 unchanged lines hidden (view full) --- 1224 * interrupt time; lock them out. 1225 */ 1226 s = splimp(); 1227 LIST_INSERT_HEAD(&ifp->if_multiaddrs, ifma, ifma_link); 1228 splx(s); 1229 *retifma = ifma; 1230 1231 if (llsa != 0) { | 1191 if (equal(sa, ifma->ifma_addr)) { 1192 ifma->ifma_refcount++; 1193 if (retifma) 1194 *retifma = ifma; 1195 return 0; 1196 } 1197 } 1198 --- 25 unchanged lines hidden (view full) --- 1224 * interrupt time; lock them out. 1225 */ 1226 s = splimp(); 1227 LIST_INSERT_HEAD(&ifp->if_multiaddrs, ifma, ifma_link); 1228 splx(s); 1229 *retifma = ifma; 1230 1231 if (llsa != 0) { |
1232 for (ifma = ifp->if_multiaddrs.lh_first; ifma; 1233 ifma = ifma->ifma_link.le_next) { | 1232 for (ifma = LIST_FIRST(&ifp->if_multiaddrs); ifma; 1233 ifma = LIST_NEXT(ifma, ifma_link)) { |
1234 if (equal(ifma->ifma_addr, llsa)) 1235 break; 1236 } 1237 if (ifma) { 1238 ifma->ifma_refcount++; 1239 } else { 1240 MALLOC(ifma, struct ifmultiaddr *, sizeof *ifma, 1241 M_IFMADDR, M_WAITOK); --- 26 unchanged lines hidden (view full) --- 1268int 1269if_delmulti(ifp, sa) 1270 struct ifnet *ifp; 1271 struct sockaddr *sa; 1272{ 1273 struct ifmultiaddr *ifma; 1274 int s; 1275 | 1234 if (equal(ifma->ifma_addr, llsa)) 1235 break; 1236 } 1237 if (ifma) { 1238 ifma->ifma_refcount++; 1239 } else { 1240 MALLOC(ifma, struct ifmultiaddr *, sizeof *ifma, 1241 M_IFMADDR, M_WAITOK); --- 26 unchanged lines hidden (view full) --- 1268int 1269if_delmulti(ifp, sa) 1270 struct ifnet *ifp; 1271 struct sockaddr *sa; 1272{ 1273 struct ifmultiaddr *ifma; 1274 int s; 1275 |
1276 for (ifma = ifp->if_multiaddrs.lh_first; ifma; 1277 ifma = ifma->ifma_link.le_next) | 1276 for (ifma = LIST_FIRST(&ifp->if_multiaddrs); ifma; 1277 ifma = LIST_NEXT(ifma, ifma_link)) |
1278 if (equal(sa, ifma->ifma_addr)) 1279 break; 1280 if (ifma == 0) 1281 return ENOENT; 1282 1283 if (ifma->ifma_refcount > 1) { 1284 ifma->ifma_refcount--; 1285 return 0; --- 15 unchanged lines hidden (view full) --- 1301 * ifma->ifma_lladdr for this purpose (so we don't have 1302 * to call ifp->if_resolvemulti() again), and we saved that 1303 * value in sa above. If some nasty deleted the 1304 * link-layer address out from underneath us, we can deal because 1305 * the address we stored was is not the same as the one which was 1306 * in the record for the link-layer address. (So we don't complain 1307 * in that case.) 1308 */ | 1278 if (equal(sa, ifma->ifma_addr)) 1279 break; 1280 if (ifma == 0) 1281 return ENOENT; 1282 1283 if (ifma->ifma_refcount > 1) { 1284 ifma->ifma_refcount--; 1285 return 0; --- 15 unchanged lines hidden (view full) --- 1301 * ifma->ifma_lladdr for this purpose (so we don't have 1302 * to call ifp->if_resolvemulti() again), and we saved that 1303 * value in sa above. If some nasty deleted the 1304 * link-layer address out from underneath us, we can deal because 1305 * the address we stored was is not the same as the one which was 1306 * in the record for the link-layer address. (So we don't complain 1307 * in that case.) 1308 */ |
1309 for (ifma = ifp->if_multiaddrs.lh_first; ifma; 1310 ifma = ifma->ifma_link.le_next) | 1309 for (ifma = LIST_FIRST(&ifp->if_multiaddrs); ifma; 1310 ifma = LIST_NEXT(ifma, ifma_link)) |
1311 if (equal(sa, ifma->ifma_addr)) 1312 break; 1313 if (ifma == 0) 1314 return 0; 1315 1316 if (ifma->ifma_refcount > 1) { 1317 ifma->ifma_refcount--; 1318 return 0; --- 58 unchanged lines hidden (view full) --- 1377 1378struct ifmultiaddr * 1379ifmaof_ifpforaddr(sa, ifp) 1380 struct sockaddr *sa; 1381 struct ifnet *ifp; 1382{ 1383 struct ifmultiaddr *ifma; 1384 | 1311 if (equal(sa, ifma->ifma_addr)) 1312 break; 1313 if (ifma == 0) 1314 return 0; 1315 1316 if (ifma->ifma_refcount > 1) { 1317 ifma->ifma_refcount--; 1318 return 0; --- 58 unchanged lines hidden (view full) --- 1377 1378struct ifmultiaddr * 1379ifmaof_ifpforaddr(sa, ifp) 1380 struct sockaddr *sa; 1381 struct ifnet *ifp; 1382{ 1383 struct ifmultiaddr *ifma; 1384 |
1385 for (ifma = ifp->if_multiaddrs.lh_first; ifma; 1386 ifma = ifma->ifma_link.le_next) | 1385 for (ifma = LIST_FIRST(&ifp->if_multiaddrs); ifma; 1386 ifma = LIST_NEXT(ifma, ifma_link)) |
1387 if (equal(ifma->ifma_addr, sa)) 1388 break; 1389 1390 return ifma; 1391} 1392 1393SYSCTL_NODE(_net, PF_LINK, link, CTLFLAG_RW, 0, "Link layers"); 1394SYSCTL_NODE(_net_link, 0, generic, CTLFLAG_RW, 0, "Generic link-management"); | 1387 if (equal(ifma->ifma_addr, sa)) 1388 break; 1389 1390 return ifma; 1391} 1392 1393SYSCTL_NODE(_net, PF_LINK, link, CTLFLAG_RW, 0, "Link layers"); 1394SYSCTL_NODE(_net_link, 0, generic, CTLFLAG_RW, 0, "Generic link-management"); |