Lines Matching refs:ifctx

271 static void         bootpc_compose_query(struct bootpc_ifcontext *ifctx,
290 static void bootpc_fakeup_interface(struct bootpc_ifcontext *ifctx,
293 static void bootpc_adjust_interface(struct bootpc_ifcontext *ifctx,
297 struct bootpc_ifcontext *ifctx,
301 struct bootpc_ifcontext *ifctx);
303 static __inline int bootpc_ifctx_isresolved(struct bootpc_ifcontext *ifctx);
304 static __inline int bootpc_ifctx_isunresolved(struct bootpc_ifcontext *ifctx);
305 static __inline int bootpc_ifctx_isfailed(struct bootpc_ifcontext *ifctx);
452 struct bootpc_ifcontext *ifctx; in allocifctx() local
454 ifctx = malloc(sizeof(*ifctx), M_TEMP, M_WAITOK | M_ZERO); in allocifctx()
455 ifctx->xid = gctx->xid; in allocifctx()
457 ifctx->state = IF_BOOTP_UNRESOLVED; in allocifctx()
459 ifctx->state = IF_DHCP_UNRESOLVED; in allocifctx()
462 STAILQ_INSERT_TAIL(&gctx->interfaces, ifctx, next); in allocifctx()
466 bootpc_ifctx_isresolved(struct bootpc_ifcontext *ifctx) in bootpc_ifctx_isresolved() argument
469 if (ifctx->state == IF_BOOTP_RESOLVED || in bootpc_ifctx_isresolved()
470 ifctx->state == IF_DHCP_RESOLVED) in bootpc_ifctx_isresolved()
476 bootpc_ifctx_isunresolved(struct bootpc_ifcontext *ifctx) in bootpc_ifctx_isunresolved() argument
479 if (ifctx->state == IF_BOOTP_UNRESOLVED || in bootpc_ifctx_isunresolved()
480 ifctx->state == IF_DHCP_UNRESOLVED) in bootpc_ifctx_isunresolved()
486 bootpc_ifctx_isfailed(struct bootpc_ifcontext *ifctx) in bootpc_ifctx_isfailed() argument
489 if (ifctx->state == IF_BOOTP_FAILED || in bootpc_ifctx_isfailed()
490 ifctx->state == IF_DHCP_FAILED) in bootpc_ifctx_isfailed()
497 struct bootpc_ifcontext *ifctx) in bootpc_received() argument
523 switch (ifctx->dhcpquerytype) { in bootpc_received()
541 if ((ifctx->state == IF_BOOTP_RESOLVED || in bootpc_received()
542 (ifctx->dhcpquerytype == DHCP_DISCOVER && in bootpc_received()
543 (ifctx->state == IF_DHCP_OFFERED || in bootpc_received()
544 ifctx->state == IF_DHCP_RESOLVED))) && in bootpc_received()
545 (bootpc_tag(&gctx->tmptag, &ifctx->reply, in bootpc_received()
546 ifctx->replylen, in bootpc_received()
553 bcopy(&gctx->reply, &ifctx->reply, gctx->replylen); in bootpc_received()
554 ifctx->replylen = gctx->replylen; in bootpc_received()
557 if (ifctx->state == IF_BOOTP_UNRESOLVED) in bootpc_received()
558 ifctx->state = IF_BOOTP_RESOLVED; in bootpc_received()
559 else if (ifctx->state == IF_DHCP_UNRESOLVED && in bootpc_received()
560 ifctx->dhcpquerytype == DHCP_DISCOVER) { in bootpc_received()
562 ifctx->state = IF_DHCP_OFFERED; in bootpc_received()
564 ifctx->state = IF_BOOTP_RESOLVED; /* Fallback */ in bootpc_received()
565 } else if (ifctx->state == IF_DHCP_OFFERED && in bootpc_received()
566 ifctx->dhcpquerytype == DHCP_REQUEST) in bootpc_received()
567 ifctx->state = IF_DHCP_RESOLVED; in bootpc_received()
570 if (ifctx->dhcpquerytype == DHCP_DISCOVER && in bootpc_received()
571 ifctx->state != IF_BOOTP_RESOLVED) { in bootpc_received()
572 p = bootpc_tag(&gctx->tmptag, &ifctx->reply, in bootpc_received()
573 ifctx->replylen, TAG_DHCP_SERVERID); in bootpc_received()
575 memcpy(&ifctx->dhcpserver, p, 4); in bootpc_received()
576 ifctx->gotdhcpserver = 1; in bootpc_received()
578 ifctx->gotdhcpserver = 0; in bootpc_received()
582 ifctx->gotrootpath = (bootpc_tag(&gctx->tmptag, &ifctx->reply, in bootpc_received()
583 ifctx->replylen, in bootpc_received()
585 ifctx->gotgw = (bootpc_tag(&gctx->tmptag, &ifctx->reply, in bootpc_received()
586 ifctx->replylen, in bootpc_received()
588 ifctx->gotnetmask = (bootpc_tag(&gctx->tmptag, &ifctx->reply, in bootpc_received()
589 ifctx->replylen, in bootpc_received()
605 struct bootpc_ifcontext *ifctx; in bootpc_call() local
675 STAILQ_FOREACH(ifctx, &gctx->interfaces, next) { in bootpc_call()
676 if (bootpc_ifctx_isresolved(ifctx) != 0 && in bootpc_call()
677 bootpc_tag(&gctx->tmptag, &ifctx->reply, in bootpc_call()
678 ifctx->replylen, in bootpc_call()
683 STAILQ_FOREACH(ifctx, &gctx->interfaces, next) { in bootpc_call()
684 struct in_aliasreq *ifra = &ifctx->iareq; in bootpc_call()
687 ifctx->outstanding = 0; in bootpc_call()
688 if (bootpc_ifctx_isresolved(ifctx) != 0 && in bootpc_call()
692 if (bootpc_ifctx_isfailed(ifctx) != 0) in bootpc_call()
696 ifctx->outstanding = 1; in bootpc_call()
699 if ((ifctx->state == IF_DHCP_OFFERED && in bootpc_call()
700 ifctx->dhcpquerytype != DHCP_REQUEST) || in bootpc_call()
701 (ifctx->state == IF_DHCP_UNRESOLVED && in bootpc_call()
702 ifctx->dhcpquerytype != DHCP_DISCOVER) || in bootpc_call()
703 (ifctx->state == IF_BOOTP_UNRESOLVED && in bootpc_call()
704 ifctx->dhcpquerytype != DHCP_NOMSG)) { in bootpc_call()
705 ifctx->sentmsg = 0; in bootpc_call()
706 bootpc_compose_query(ifctx, td); in bootpc_call()
711 if (ifctx->sentmsg == 0) { in bootpc_call()
712 switch(ifctx->dhcpquerytype) { in bootpc_call()
727 ifctx->ireq.ifr_name, in bootpc_call()
728 ifctx->sdl->sdl_alen, in bootpc_call()
729 (unsigned char *) LLADDR(ifctx->sdl) ); in bootpc_call()
730 ifctx->sentmsg = 1; in bootpc_call()
733 aio.iov_base = (void *) &ifctx->call; in bootpc_call()
734 aio.iov_len = sizeof(ifctx->call); in bootpc_call()
741 auio.uio_resid = sizeof(ifctx->call); in bootpc_call()
803 STAILQ_FOREACH(ifctx, &gctx->interfaces, next) { in bootpc_call()
804 if (bootpc_ifctx_isresolved(ifctx) != 0 || in bootpc_call()
805 bootpc_ifctx_isfailed(ifctx) != 0) in bootpc_call()
808 ifctx->call.secs = htons(gctx->secs); in bootpc_call()
826 STAILQ_FOREACH(ifctx, &gctx->interfaces, next) { in bootpc_call()
827 if (gctx->reply.xid != ifctx->call.xid) in bootpc_call()
831 if (gctx->reply.hlen != ifctx->call.hlen) in bootpc_call()
836 ifctx->call.chaddr, in bootpc_call()
837 ifctx->call.hlen) != 0) in bootpc_call()
843 if (ifctx != NULL) { in bootpc_call()
866 ifctx->ireq.ifr_name); in bootpc_call()
873 if (bootpc_received(gctx, ifctx) != 0) { in bootpc_call()
875 if (ifctx->outstanding) { in bootpc_call()
876 ifctx->outstanding = 0; in bootpc_call()
885 if (ifctx->gotrootpath || in bootpc_call()
890 if (ifctx->gotrootpath) in bootpc_call()
902 STAILQ_FOREACH(ifctx, &gctx->interfaces, next) in bootpc_call()
903 if (ifctx->state == IF_DHCP_OFFERED) { in bootpc_call()
904 if (ifctx->dhcpquerytype == DHCP_DISCOVER) in bootpc_call()
907 ifctx->state = IF_DHCP_UNRESOLVED; in bootpc_call()
925 STAILQ_FOREACH(ifctx, &gctx->interfaces, next) in bootpc_call()
926 if (bootpc_ifctx_isresolved(ifctx) == 0) { in bootpc_call()
928 ifctx->dhcpquerytype != DHCP_NOMSG ? in bootpc_call()
930 ifctx->ireq.ifr_name); in bootpc_call()
941 STAILQ_FOREACH(ifctx, &gctx->interfaces, next) in bootpc_call()
942 if (bootpc_ifctx_isresolved(ifctx) != 0) { in bootpc_call()
954 bootpc_fakeup_interface(struct bootpc_ifcontext *ifctx, struct lwp *td) in bootpc_fakeup_interface() argument
961 ifr = &ifctx->ireq; in bootpc_fakeup_interface()
962 ifra = &ifctx->iareq; in bootpc_fakeup_interface()
997 bootpc_shutdown_interface(struct bootpc_ifcontext *ifctx, struct lwp *td) in bootpc_shutdown_interface() argument
1003 ifr = &ifctx->ireq; in bootpc_shutdown_interface()
1005 printf("Shutdown interface %s\n", ifctx->ireq.ifr_name); in bootpc_shutdown_interface()
1022 bootpc_adjust_interface(struct bootpc_ifcontext *ifctx, in bootpc_adjust_interface() argument
1032 ifr = &ifctx->ireq; in bootpc_adjust_interface()
1033 ifra = &ifctx->iareq; in bootpc_adjust_interface()
1034 myaddr = &ifctx->myaddr; in bootpc_adjust_interface()
1035 netmask = &ifctx->netmask; in bootpc_adjust_interface()
1037 if (bootpc_ifctx_isresolved(ifctx) == 0) { in bootpc_adjust_interface()
1039 bootpc_shutdown_interface(ifctx, td); in bootpc_adjust_interface()
1043 printf("Adjusted interface %s", ifctx->ireq.ifr_name); in bootpc_adjust_interface()
1046 if (ifctx->mtu != 0) { in bootpc_adjust_interface()
1047 printf(" (MTU=%d%s)", ifctx->mtu, in bootpc_adjust_interface()
1048 (ifctx->mtu > 1514) ? "/JUMBO" : ""); in bootpc_adjust_interface()
1049 ifr->ifr_mtu = ifctx->mtu; in bootpc_adjust_interface()
1078 bootpc_add_default_route(struct bootpc_ifcontext *ifctx) in bootpc_add_default_route() argument
1084 if (ifctx->gw.sin_addr.s_addr == htonl(INADDR_ANY)) in bootpc_add_default_route()
1091 (struct sockaddr *) &ifctx->gw, (struct sockaddr *)&defmask, in bootpc_add_default_route()
1099 bootpc_remove_default_route(struct bootpc_ifcontext *ifctx) in bootpc_remove_default_route() argument
1105 if (ifctx->gw.sin_addr.s_addr == htonl(INADDR_ANY)) in bootpc_remove_default_route()
1112 (struct sockaddr *) &ifctx->gw, (struct sockaddr *)&defmask, in bootpc_remove_default_route()
1259 bootpc_compose_query(struct bootpc_ifcontext *ifctx, struct lwp *td) in bootpc_compose_query() argument
1266 ifctx->gotrootpath = 0; in bootpc_compose_query()
1268 bzero((void *) &ifctx->call, sizeof(ifctx->call)); in bootpc_compose_query()
1271 ifctx->call.op = BOOTP_REQUEST; /* BOOTREQUEST */ in bootpc_compose_query()
1272 ifctx->call.htype = 1; /* 10mb ethernet */ in bootpc_compose_query()
1273 ifctx->call.hlen = ifctx->sdl->sdl_alen;/* Hardware address length */ in bootpc_compose_query()
1274 ifctx->call.hops = 0; in bootpc_compose_query()
1275 if (bootpc_ifctx_isunresolved(ifctx) != 0) in bootpc_compose_query()
1276 ifctx->xid++; in bootpc_compose_query()
1277 ifctx->call.xid = txdr_unsigned(ifctx->xid); in bootpc_compose_query()
1278 bcopy(LLADDR(ifctx->sdl), &ifctx->call.chaddr, ifctx->sdl->sdl_alen); in bootpc_compose_query()
1280 vendp = ifctx->call.vend; in bootpc_compose_query()
1297 ifctx->dhcpquerytype = DHCP_NOMSG; in bootpc_compose_query()
1298 switch (ifctx->state) { in bootpc_compose_query()
1303 ifctx->dhcpquerytype = DHCP_DISCOVER; in bootpc_compose_query()
1304 ifctx->gotdhcpserver = 0; in bootpc_compose_query()
1310 ifctx->dhcpquerytype = DHCP_REQUEST; in bootpc_compose_query()
1313 memcpy(vendp, &ifctx->reply.yiaddr, 4); in bootpc_compose_query()
1315 if (ifctx->gotdhcpserver != 0) { in bootpc_compose_query()
1318 memcpy(vendp, &ifctx->dhcpserver, 4); in bootpc_compose_query()
1332 ifctx->call.secs = 0; in bootpc_compose_query()
1333 ifctx->call.flags = htons(0x8000); /* We need a broadcast answer */ in bootpc_compose_query()
1421 bootpc_decode_reply(struct nfsv3_diskless *nd, struct bootpc_ifcontext *ifctx, in bootpc_decode_reply() argument
1426 ifctx->gotgw = 0; in bootpc_decode_reply()
1427 ifctx->gotnetmask = 0; in bootpc_decode_reply()
1429 clear_sinaddr(&ifctx->myaddr); in bootpc_decode_reply()
1430 clear_sinaddr(&ifctx->netmask); in bootpc_decode_reply()
1431 clear_sinaddr(&ifctx->gw); in bootpc_decode_reply()
1433 ifctx->myaddr.sin_addr = ifctx->reply.yiaddr; in bootpc_decode_reply()
1435 printf("%s at ", ifctx->ireq.ifr_name); in bootpc_decode_reply()
1436 print_sin_addr(&ifctx->myaddr); in bootpc_decode_reply()
1438 print_in_addr(ifctx->reply.siaddr); in bootpc_decode_reply()
1440 ifctx->gw.sin_addr = ifctx->reply.giaddr; in bootpc_decode_reply()
1441 if (ifctx->reply.giaddr.s_addr != htonl(INADDR_ANY)) { in bootpc_decode_reply()
1443 print_in_addr(ifctx->reply.giaddr); in bootpc_decode_reply()
1448 &ifctx->reply, ifctx->replylen, TAG_END); in bootpc_decode_reply()
1451 if (ifctx->reply.sname[0] != '\0') in bootpc_decode_reply()
1452 printf(" server name %s", ifctx->reply.sname); in bootpc_decode_reply()
1454 if (ifctx->reply.file[0] != '\0') in bootpc_decode_reply()
1455 printf(" boot file %s", ifctx->reply.file); in bootpc_decode_reply()
1459 p = bootpc_tag(&gctx->tag, &ifctx->reply, ifctx->replylen, in bootpc_decode_reply()
1465 bcopy(p, &ifctx->netmask.sin_addr, 4); in bootpc_decode_reply()
1466 ifctx->gotnetmask = 1; in bootpc_decode_reply()
1468 print_sin_addr(&ifctx->netmask); in bootpc_decode_reply()
1472 p = bootpc_tag(&gctx->tag, &ifctx->reply, ifctx->replylen, in bootpc_decode_reply()
1479 bcopy(p, &ifctx->gw.sin_addr, 4); in bootpc_decode_reply()
1481 print_sin_addr(&ifctx->gw); in bootpc_decode_reply()
1483 ifctx->gotgw = 1; in bootpc_decode_reply()
1503 p = bootpc_tag(&gctx->tag, &ifctx->reply, ifctx->replylen, in bootpc_decode_reply()
1506 ifctx->gotrootpath = 1; in bootpc_decode_reply()
1518 nd->root_hostnam, p, &ifctx->reply.siaddr)) { in bootpc_decode_reply()
1526 gctx->setrootfs = ifctx; in bootpc_decode_reply()
1528 p = bootpc_tag(&gctx->tag, &ifctx->reply, in bootpc_decode_reply()
1529 ifctx->replylen, in bootpc_decode_reply()
1539 p = bootpc_tag(&gctx->tag, &ifctx->reply, ifctx->replylen, in bootpc_decode_reply()
1553 gctx->sethostname = ifctx; in bootpc_decode_reply()
1556 p = bootpc_tag(&gctx->tag, &ifctx->reply, ifctx->replylen, in bootpc_decode_reply()
1565 p = bootpc_tag(&gctx->tag, &ifctx->reply, ifctx->replylen, in bootpc_decode_reply()
1568 ifctx->mtu = be16dec(p); in bootpc_decode_reply()
1573 if (ifctx->gotnetmask == 0) { in bootpc_decode_reply()
1574 if (IN_CLASSA(ntohl(ifctx->myaddr.sin_addr.s_addr))) in bootpc_decode_reply()
1575 ifctx->netmask.sin_addr.s_addr = htonl(IN_CLASSA_NET); in bootpc_decode_reply()
1576 else if (IN_CLASSB(ntohl(ifctx->myaddr.sin_addr.s_addr))) in bootpc_decode_reply()
1577 ifctx->netmask.sin_addr.s_addr = htonl(IN_CLASSB_NET); in bootpc_decode_reply()
1579 ifctx->netmask.sin_addr.s_addr = htonl(IN_CLASSC_NET); in bootpc_decode_reply()
1586 struct bootpc_ifcontext *ifctx; /* Interface BOOTP contexts */ in bootpc_init() local
1666 ifctx = STAILQ_FIRST(&gctx->interfaces); in bootpc_init()
1669 if (ifctx == NULL) in bootpc_init()
1688 strlcpy(ifctx->ireq.ifr_name, ifp->if_xname, in bootpc_init()
1689 sizeof(ifctx->ireq.ifr_name)); in bootpc_init()
1690 ifctx->ifp = ifp; in bootpc_init()
1702 ifctx->ireq.ifr_name); in bootpc_init()
1703 ifctx->sdl = sdl; in bootpc_init()
1705 ifctx = STAILQ_NEXT(ifctx, next); in bootpc_init()
1730 STAILQ_FOREACH(ifctx, &gctx->interfaces, next) in bootpc_init()
1731 bootpc_fakeup_interface(ifctx, td); in bootpc_init()
1733 STAILQ_FOREACH(ifctx, &gctx->interfaces, next) in bootpc_init()
1734 bootpc_compose_query(ifctx, td); in bootpc_init()
1743 STAILQ_FOREACH(ifctx, &gctx->interfaces, next) in bootpc_init()
1744 if (bootpc_ifctx_isresolved(ifctx) != 0) in bootpc_init()
1745 bootpc_decode_reply(nd, ifctx, gctx); in bootpc_init()
1752 STAILQ_FOREACH(ifctx, &gctx->interfaces, next) in bootpc_init()
1753 bootpc_adjust_interface(ifctx, gctx, td); in bootpc_init()
1757 STAILQ_FOREACH(ifctx, &gctx->interfaces, next) in bootpc_init()
1758 if (ifctx->gotrootpath != 0) in bootpc_init()
1760 if (ifctx == NULL) { in bootpc_init()
1761 STAILQ_FOREACH(ifctx, &gctx->interfaces, next) in bootpc_init()
1762 if (bootpc_ifctx_isresolved(ifctx) != 0) in bootpc_init()
1765 if (ifctx == NULL) in bootpc_init()
1770 kern_setenv("boot.netif.name", ifctx->ifp->if_xname); in bootpc_init()
1772 bootpc_add_default_route(ifctx); in bootpc_init()
1776 bootpc_remove_default_route(ifctx); in bootpc_init()
1787 strcpy(nd->myif.ifra_name, ifctx->ireq.ifr_name); in bootpc_init()
1788 bcopy(&ifctx->myaddr, &nd->myif.ifra_addr, sizeof(ifctx->myaddr)); in bootpc_init()
1789 bcopy(&ifctx->myaddr, &nd->myif.ifra_broadaddr, sizeof(ifctx->myaddr)); in bootpc_init()
1791 ifctx->myaddr.sin_addr.s_addr | in bootpc_init()
1792 ~ ifctx->netmask.sin_addr.s_addr; in bootpc_init()
1793 bcopy(&ifctx->netmask, &nd->myif.ifra_mask, sizeof(ifctx->netmask)); in bootpc_init()
1794 bcopy(&ifctx->gw, &nd->mygateway, sizeof(ifctx->gw)); in bootpc_init()
1797 while((ifctx = STAILQ_FIRST(&gctx->interfaces)) != NULL) { in bootpc_init()
1799 free(ifctx, M_TEMP); in bootpc_init()