Lines Matching refs:ifctx

256 static void	bootpc_compose_query(struct bootpc_ifcontext *ifctx,
270 static void bootpc_fakeup_interface(struct bootpc_ifcontext *ifctx,
273 static void bootpc_adjust_interface(struct bootpc_ifcontext *ifctx,
277 struct bootpc_ifcontext *ifctx,
281 struct bootpc_ifcontext *ifctx);
283 static __inline int bootpc_ifctx_isresolved(struct bootpc_ifcontext *ifctx);
284 static __inline int bootpc_ifctx_isunresolved(struct bootpc_ifcontext *ifctx);
285 static __inline int bootpc_ifctx_isfailed(struct bootpc_ifcontext *ifctx);
341 struct bootpc_ifcontext *ifctx; in allocifctx() local
343 ifctx = malloc(sizeof(*ifctx), M_TEMP, M_WAITOK | M_ZERO); in allocifctx()
344 ifctx->xid = gctx->xid; in allocifctx()
346 ifctx->state = IF_BOOTP_UNRESOLVED; in allocifctx()
348 ifctx->state = IF_DHCP_UNRESOLVED; in allocifctx()
351 STAILQ_INSERT_TAIL(&gctx->interfaces, ifctx, next); in allocifctx()
355 bootpc_ifctx_isresolved(struct bootpc_ifcontext *ifctx) in bootpc_ifctx_isresolved() argument
358 if (ifctx->state == IF_BOOTP_RESOLVED || in bootpc_ifctx_isresolved()
359 ifctx->state == IF_DHCP_RESOLVED) in bootpc_ifctx_isresolved()
365 bootpc_ifctx_isunresolved(struct bootpc_ifcontext *ifctx) in bootpc_ifctx_isunresolved() argument
368 if (ifctx->state == IF_BOOTP_UNRESOLVED || in bootpc_ifctx_isunresolved()
369 ifctx->state == IF_DHCP_UNRESOLVED) in bootpc_ifctx_isunresolved()
375 bootpc_ifctx_isfailed(struct bootpc_ifcontext *ifctx) in bootpc_ifctx_isfailed() argument
378 if (ifctx->state == IF_BOOTP_FAILED || in bootpc_ifctx_isfailed()
379 ifctx->state == IF_DHCP_FAILED) in bootpc_ifctx_isfailed()
386 struct bootpc_ifcontext *ifctx) in bootpc_received() argument
412 switch (ifctx->dhcpquerytype) { in bootpc_received()
430 if ((ifctx->state == IF_BOOTP_RESOLVED || in bootpc_received()
431 (ifctx->dhcpquerytype == DHCP_DISCOVER && in bootpc_received()
432 (ifctx->state == IF_DHCP_OFFERED || in bootpc_received()
433 ifctx->state == IF_DHCP_RESOLVED))) && in bootpc_received()
434 (bootpc_tag(&gctx->tmptag, &ifctx->reply, in bootpc_received()
435 ifctx->replylen, in bootpc_received()
442 bcopy(&gctx->reply, &ifctx->reply, gctx->replylen); in bootpc_received()
443 ifctx->replylen = gctx->replylen; in bootpc_received()
446 if (ifctx->state == IF_BOOTP_UNRESOLVED) in bootpc_received()
447 ifctx->state = IF_BOOTP_RESOLVED; in bootpc_received()
448 else if (ifctx->state == IF_DHCP_UNRESOLVED && in bootpc_received()
449 ifctx->dhcpquerytype == DHCP_DISCOVER) { in bootpc_received()
451 ifctx->state = IF_DHCP_OFFERED; in bootpc_received()
453 ifctx->state = IF_BOOTP_RESOLVED; /* Fallback */ in bootpc_received()
454 } else if (ifctx->state == IF_DHCP_OFFERED && in bootpc_received()
455 ifctx->dhcpquerytype == DHCP_REQUEST) in bootpc_received()
456 ifctx->state = IF_DHCP_RESOLVED; in bootpc_received()
458 if (ifctx->dhcpquerytype == DHCP_DISCOVER && in bootpc_received()
459 ifctx->state != IF_BOOTP_RESOLVED) { in bootpc_received()
460 p = bootpc_tag(&gctx->tmptag, &ifctx->reply, in bootpc_received()
461 ifctx->replylen, TAG_DHCP_SERVERID); in bootpc_received()
463 memcpy(&ifctx->dhcpserver, p, 4); in bootpc_received()
464 ifctx->gotdhcpserver = 1; in bootpc_received()
466 ifctx->gotdhcpserver = 0; in bootpc_received()
470 ifctx->gotrootpath = (bootpc_tag(&gctx->tmptag, &ifctx->reply, in bootpc_received()
471 ifctx->replylen, in bootpc_received()
473 ifctx->gotgw = (bootpc_tag(&gctx->tmptag, &ifctx->reply, in bootpc_received()
474 ifctx->replylen, in bootpc_received()
476 ifctx->gotnetmask = (bootpc_tag(&gctx->tmptag, &ifctx->reply, in bootpc_received()
477 ifctx->replylen, in bootpc_received()
493 struct bootpc_ifcontext *ifctx; in bootpc_call() local
568 STAILQ_FOREACH(ifctx, &gctx->interfaces, next) { in bootpc_call()
569 if (bootpc_ifctx_isresolved(ifctx) != 0 && in bootpc_call()
570 bootpc_tag(&gctx->tmptag, &ifctx->reply, in bootpc_call()
571 ifctx->replylen, in bootpc_call()
576 STAILQ_FOREACH(ifctx, &gctx->interfaces, next) { in bootpc_call()
577 struct in_aliasreq *ifra = &ifctx->iareq; in bootpc_call()
580 ifctx->outstanding = 0; in bootpc_call()
581 if (bootpc_ifctx_isresolved(ifctx) != 0 && in bootpc_call()
585 if (bootpc_ifctx_isfailed(ifctx) != 0) in bootpc_call()
589 ifctx->outstanding = 1; in bootpc_call()
592 if ((ifctx->state == IF_DHCP_OFFERED && in bootpc_call()
593 ifctx->dhcpquerytype != DHCP_REQUEST) || in bootpc_call()
594 (ifctx->state == IF_DHCP_UNRESOLVED && in bootpc_call()
595 ifctx->dhcpquerytype != DHCP_DISCOVER) || in bootpc_call()
596 (ifctx->state == IF_BOOTP_UNRESOLVED && in bootpc_call()
597 ifctx->dhcpquerytype != DHCP_NOMSG)) { in bootpc_call()
598 ifctx->sentmsg = 0; in bootpc_call()
599 bootpc_compose_query(ifctx, td); in bootpc_call()
604 if (ifctx->sentmsg == 0) { in bootpc_call()
605 switch(ifctx->dhcpquerytype) { in bootpc_call()
620 ifctx->ireq.ifr_name, in bootpc_call()
621 ifctx->sdl->sdl_alen, in bootpc_call()
622 (unsigned char *) LLADDR(ifctx->sdl), in bootpc_call()
624 ifctx->sentmsg = 1; in bootpc_call()
627 aio.iov_base = (caddr_t) &ifctx->call; in bootpc_call()
628 aio.iov_len = sizeof(ifctx->call); in bootpc_call()
635 auio.uio_resid = sizeof(ifctx->call); in bootpc_call()
697 STAILQ_FOREACH(ifctx, &gctx->interfaces, next) { in bootpc_call()
698 if (bootpc_ifctx_isresolved(ifctx) != 0 || in bootpc_call()
699 bootpc_ifctx_isfailed(ifctx) != 0) in bootpc_call()
702 ifctx->call.secs = htons(gctx->secs); in bootpc_call()
720 STAILQ_FOREACH(ifctx, &gctx->interfaces, next) { in bootpc_call()
721 if (gctx->reply.xid != ifctx->call.xid) in bootpc_call()
725 if (gctx->reply.hlen != ifctx->call.hlen) in bootpc_call()
730 ifctx->call.chaddr, in bootpc_call()
731 ifctx->call.hlen) != 0) in bootpc_call()
737 if (ifctx != NULL) { in bootpc_call()
760 ifctx->ireq.ifr_name); in bootpc_call()
767 if (bootpc_received(gctx, ifctx) != 0) { in bootpc_call()
769 if (ifctx->outstanding) { in bootpc_call()
770 ifctx->outstanding = 0; in bootpc_call()
779 if (ifctx->gotrootpath || in bootpc_call()
784 if (ifctx->gotrootpath) in bootpc_call()
796 STAILQ_FOREACH(ifctx, &gctx->interfaces, next) in bootpc_call()
797 if (ifctx->state == IF_DHCP_OFFERED) { in bootpc_call()
798 if (ifctx->dhcpquerytype == DHCP_DISCOVER) in bootpc_call()
801 ifctx->state = IF_DHCP_UNRESOLVED; in bootpc_call()
819 STAILQ_FOREACH(ifctx, &gctx->interfaces, next) in bootpc_call()
820 if (bootpc_ifctx_isresolved(ifctx) == 0) { in bootpc_call()
822 ifctx->dhcpquerytype != DHCP_NOMSG ? in bootpc_call()
824 ifctx->ireq.ifr_name); in bootpc_call()
835 STAILQ_FOREACH(ifctx, &gctx->interfaces, next) in bootpc_call()
836 if (bootpc_ifctx_isresolved(ifctx) != 0) { in bootpc_call()
848 bootpc_fakeup_interface(struct bootpc_ifcontext *ifctx, struct thread *td) in bootpc_fakeup_interface() argument
855 ifr = &ifctx->ireq; in bootpc_fakeup_interface()
856 ifra = &ifctx->iareq; in bootpc_fakeup_interface()
891 bootpc_shutdown_interface(struct bootpc_ifcontext *ifctx, struct thread *td) in bootpc_shutdown_interface() argument
897 ifr = &ifctx->ireq; in bootpc_shutdown_interface()
899 printf("Shutdown interface %s\n", ifctx->ireq.ifr_name); in bootpc_shutdown_interface()
916 bootpc_adjust_interface(struct bootpc_ifcontext *ifctx, in bootpc_adjust_interface() argument
926 ifr = &ifctx->ireq; in bootpc_adjust_interface()
927 ifra = &ifctx->iareq; in bootpc_adjust_interface()
928 myaddr = &ifctx->myaddr; in bootpc_adjust_interface()
929 netmask = &ifctx->netmask; in bootpc_adjust_interface()
931 if (bootpc_ifctx_isresolved(ifctx) == 0) { in bootpc_adjust_interface()
933 bootpc_shutdown_interface(ifctx, td); in bootpc_adjust_interface()
937 printf("Adjusted interface %s", ifctx->ireq.ifr_name); in bootpc_adjust_interface()
940 if (ifctx->mtu != 0) { in bootpc_adjust_interface()
941 printf(" (MTU=%d%s)", ifctx->mtu, in bootpc_adjust_interface()
942 (ifctx->mtu > 1514) ? "/JUMBO" : ""); in bootpc_adjust_interface()
943 ifr->ifr_mtu = ifctx->mtu; in bootpc_adjust_interface()
972 bootpc_add_default_route(struct bootpc_ifcontext *ifctx) in bootpc_add_default_route() argument
980 if (ifctx->gw.sin_addr.s_addr == htonl(INADDR_ANY)) in bootpc_add_default_route()
990 info.rti_info[RTAX_GATEWAY] = (struct sockaddr *)&ifctx->gw; in bootpc_add_default_route()
1000 bootpc_remove_default_route(struct bootpc_ifcontext *ifctx) in bootpc_remove_default_route() argument
1008 if (ifctx->gw.sin_addr.s_addr == htonl(INADDR_ANY)) in bootpc_remove_default_route()
1018 info.rti_info[RTAX_GATEWAY] = (struct sockaddr *)&ifctx->gw; in bootpc_remove_default_route()
1166 bootpc_compose_query(struct bootpc_ifcontext *ifctx, struct thread *td) in bootpc_compose_query() argument
1173 ifctx->gotrootpath = 0; in bootpc_compose_query()
1175 bzero((caddr_t) &ifctx->call, sizeof(ifctx->call)); in bootpc_compose_query()
1178 ifctx->call.op = BOOTP_REQUEST; /* BOOTREQUEST */ in bootpc_compose_query()
1179 ifctx->call.htype = 1; /* 10mb ethernet */ in bootpc_compose_query()
1180 ifctx->call.hlen = ifctx->sdl->sdl_alen;/* Hardware address length */ in bootpc_compose_query()
1181 ifctx->call.hops = 0; in bootpc_compose_query()
1182 if (bootpc_ifctx_isunresolved(ifctx) != 0) in bootpc_compose_query()
1183 ifctx->xid++; in bootpc_compose_query()
1184 ifctx->call.xid = txdr_unsigned(ifctx->xid); in bootpc_compose_query()
1185 bcopy(LLADDR(ifctx->sdl), &ifctx->call.chaddr, ifctx->sdl->sdl_alen); in bootpc_compose_query()
1187 vendp = ifctx->call.vend; in bootpc_compose_query()
1204 ifctx->dhcpquerytype = DHCP_NOMSG; in bootpc_compose_query()
1205 switch (ifctx->state) { in bootpc_compose_query()
1210 ifctx->dhcpquerytype = DHCP_DISCOVER; in bootpc_compose_query()
1211 ifctx->gotdhcpserver = 0; in bootpc_compose_query()
1217 ifctx->dhcpquerytype = DHCP_REQUEST; in bootpc_compose_query()
1220 memcpy(vendp, &ifctx->reply.yiaddr, 4); in bootpc_compose_query()
1222 if (ifctx->gotdhcpserver != 0) { in bootpc_compose_query()
1225 memcpy(vendp, &ifctx->dhcpserver, 4); in bootpc_compose_query()
1239 ifctx->call.secs = 0; in bootpc_compose_query()
1240 ifctx->call.flags = htons(0x8000); /* We need a broadcast answer */ in bootpc_compose_query()
1328 bootpc_decode_reply(struct nfsv3_diskless *nd, struct bootpc_ifcontext *ifctx, in bootpc_decode_reply() argument
1333 ifctx->gotgw = 0; in bootpc_decode_reply()
1334 ifctx->gotnetmask = 0; in bootpc_decode_reply()
1336 clear_sinaddr(&ifctx->myaddr); in bootpc_decode_reply()
1337 clear_sinaddr(&ifctx->netmask); in bootpc_decode_reply()
1338 clear_sinaddr(&ifctx->gw); in bootpc_decode_reply()
1340 ifctx->myaddr.sin_addr = ifctx->reply.yiaddr; in bootpc_decode_reply()
1342 printf("%s at ", ifctx->ireq.ifr_name); in bootpc_decode_reply()
1343 print_sin_addr(&ifctx->myaddr); in bootpc_decode_reply()
1345 print_in_addr(ifctx->reply.siaddr); in bootpc_decode_reply()
1347 ifctx->gw.sin_addr = ifctx->reply.giaddr; in bootpc_decode_reply()
1348 if (ifctx->reply.giaddr.s_addr != htonl(INADDR_ANY)) { in bootpc_decode_reply()
1350 print_in_addr(ifctx->reply.giaddr); in bootpc_decode_reply()
1355 &ifctx->reply, ifctx->replylen, TAG_END); in bootpc_decode_reply()
1358 if (ifctx->reply.sname[0] != '\0') in bootpc_decode_reply()
1359 printf(" server name %s", ifctx->reply.sname); in bootpc_decode_reply()
1361 if (ifctx->reply.file[0] != '\0') in bootpc_decode_reply()
1362 printf(" boot file %s", ifctx->reply.file); in bootpc_decode_reply()
1366 p = bootpc_tag(&gctx->tag, &ifctx->reply, ifctx->replylen, in bootpc_decode_reply()
1372 bcopy(p, &ifctx->netmask.sin_addr, 4); in bootpc_decode_reply()
1373 ifctx->gotnetmask = 1; in bootpc_decode_reply()
1375 print_sin_addr(&ifctx->netmask); in bootpc_decode_reply()
1379 p = bootpc_tag(&gctx->tag, &ifctx->reply, ifctx->replylen, in bootpc_decode_reply()
1386 bcopy(p, &ifctx->gw.sin_addr, 4); in bootpc_decode_reply()
1388 print_sin_addr(&ifctx->gw); in bootpc_decode_reply()
1390 ifctx->gotgw = 1; in bootpc_decode_reply()
1410 p = bootpc_tag(&gctx->tag, &ifctx->reply, ifctx->replylen, in bootpc_decode_reply()
1413 ifctx->gotrootpath = 1; in bootpc_decode_reply()
1425 nd->root_hostnam, p, &ifctx->reply.siaddr)) { in bootpc_decode_reply()
1433 gctx->setrootfs = ifctx; in bootpc_decode_reply()
1435 p = bootpc_tag(&gctx->tag, &ifctx->reply, in bootpc_decode_reply()
1436 ifctx->replylen, in bootpc_decode_reply()
1446 p = bootpc_tag(&gctx->tag, &ifctx->reply, ifctx->replylen, in bootpc_decode_reply()
1460 gctx->sethostname = ifctx; in bootpc_decode_reply()
1463 p = bootpc_tag(&gctx->tag, &ifctx->reply, ifctx->replylen, in bootpc_decode_reply()
1472 p = bootpc_tag(&gctx->tag, &ifctx->reply, ifctx->replylen, in bootpc_decode_reply()
1475 ifctx->mtu = be16dec(p); in bootpc_decode_reply()
1480 if (ifctx->gotnetmask == 0) { in bootpc_decode_reply()
1485 printf("%s: no netmask received!\n", ifctx->ireq.ifr_name); in bootpc_decode_reply()
1486 if (IN_CLASSA(ntohl(ifctx->myaddr.sin_addr.s_addr))) in bootpc_decode_reply()
1487 ifctx->netmask.sin_addr.s_addr = htonl(IN_CLASSA_NET); in bootpc_decode_reply()
1488 else if (IN_CLASSB(ntohl(ifctx->myaddr.sin_addr.s_addr))) in bootpc_decode_reply()
1489 ifctx->netmask.sin_addr.s_addr = htonl(IN_CLASSB_NET); in bootpc_decode_reply()
1491 ifctx->netmask.sin_addr.s_addr = htonl(IN_CLASSC_NET); in bootpc_decode_reply()
1515 struct bootpc_ifcontext *ifctx = NULL; /* Interface BOOTP contexts */ in bootpc_init() local
1606 ifctx = STAILQ_FIRST(&gctx->interfaces); in bootpc_init()
1609 if (ifctx == NULL) in bootpc_init()
1626 strlcpy(ifctx->ireq.ifr_name, if_name(ifp), in bootpc_init()
1627 sizeof(ifctx->ireq.ifr_name)); in bootpc_init()
1628 ifctx->ifp = ifp; in bootpc_init()
1635 ifctx->ireq.ifr_name); in bootpc_init()
1636 ifctx->sdl = sdl; in bootpc_init()
1638 ifctx = STAILQ_NEXT(ifctx, next); in bootpc_init()
1664 STAILQ_FOREACH(ifctx, &gctx->interfaces, next) in bootpc_init()
1665 bootpc_fakeup_interface(ifctx, td); in bootpc_init()
1667 STAILQ_FOREACH(ifctx, &gctx->interfaces, next) in bootpc_init()
1668 bootpc_compose_query(ifctx, td); in bootpc_init()
1677 STAILQ_FOREACH(ifctx, &gctx->interfaces, next) in bootpc_init()
1678 if (bootpc_ifctx_isresolved(ifctx) != 0) in bootpc_init()
1679 bootpc_decode_reply(nd, ifctx, gctx); in bootpc_init()
1686 STAILQ_FOREACH(ifctx, &gctx->interfaces, next) in bootpc_init()
1687 bootpc_adjust_interface(ifctx, gctx, td); in bootpc_init()
1691 STAILQ_FOREACH(ifctx, &gctx->interfaces, next) in bootpc_init()
1692 if (ifctx->gotrootpath != 0) in bootpc_init()
1694 if (ifctx == NULL) { in bootpc_init()
1695 STAILQ_FOREACH(ifctx, &gctx->interfaces, next) in bootpc_init()
1696 if (bootpc_ifctx_isresolved(ifctx) != 0) in bootpc_init()
1699 if (ifctx == NULL) in bootpc_init()
1705 kern_setenv("boot.netif.name", if_name(ifctx->ifp)); in bootpc_init()
1708 bootpc_add_default_route(ifctx); in bootpc_init()
1714 bootpc_remove_default_route(ifctx); in bootpc_init()
1726 strcpy(nd->myif.ifra_name, ifctx->ireq.ifr_name); in bootpc_init()
1727 bcopy(&ifctx->myaddr, &nd->myif.ifra_addr, sizeof(ifctx->myaddr)); in bootpc_init()
1728 bcopy(&ifctx->myaddr, &nd->myif.ifra_broadaddr, sizeof(ifctx->myaddr)); in bootpc_init()
1730 ifctx->myaddr.sin_addr.s_addr | in bootpc_init()
1731 ~ ifctx->netmask.sin_addr.s_addr; in bootpc_init()
1732 bcopy(&ifctx->netmask, &nd->myif.ifra_mask, sizeof(ifctx->netmask)); in bootpc_init()
1733 bcopy(&ifctx->gw, &nd->mygateway, sizeof(ifctx->gw)); in bootpc_init()
1736 while((ifctx = STAILQ_FIRST(&gctx->interfaces)) != NULL) { in bootpc_init()
1738 free(ifctx, M_TEMP); in bootpc_init()