Lines Matching defs:ifctx

250 static void	bootpc_compose_query(struct bootpc_ifcontext *ifctx,
269 static void bootpc_fakeup_interface(struct bootpc_ifcontext *ifctx,
272 static int bootpc_adjust_interface(struct bootpc_ifcontext *ifctx,
276 struct bootpc_ifcontext *ifctx,
280 struct bootpc_ifcontext *ifctx);
282 static __inline int bootpc_ifctx_isresolved(struct bootpc_ifcontext *ifctx);
283 static __inline int bootpc_ifctx_isunresolved(struct bootpc_ifcontext *ifctx);
284 static __inline int bootpc_ifctx_isfailed(struct bootpc_ifcontext *ifctx);
431 struct bootpc_ifcontext *ifctx;
433 ifctx = malloc(sizeof(*ifctx), M_TEMP, M_WAITOK | M_ZERO);
434 ifctx->xid = gctx->xid;
436 ifctx->state = IF_BOOTP_UNRESOLVED;
438 ifctx->state = IF_DHCP_UNRESOLVED;
441 STAILQ_INSERT_TAIL(&gctx->interfaces, ifctx, next);
445 bootpc_ifctx_isresolved(struct bootpc_ifcontext *ifctx)
448 if (ifctx->state == IF_BOOTP_RESOLVED ||
449 ifctx->state == IF_DHCP_RESOLVED)
455 bootpc_ifctx_isunresolved(struct bootpc_ifcontext *ifctx)
458 if (ifctx->state == IF_BOOTP_UNRESOLVED ||
459 ifctx->state == IF_DHCP_UNRESOLVED)
465 bootpc_ifctx_isfailed(struct bootpc_ifcontext *ifctx)
468 if (ifctx->state == IF_BOOTP_FAILED ||
469 ifctx->state == IF_DHCP_FAILED)
476 struct bootpc_ifcontext *ifctx)
502 switch (ifctx->dhcpquerytype) {
520 if ((ifctx->state == IF_BOOTP_RESOLVED ||
521 (ifctx->dhcpquerytype == DHCP_DISCOVER &&
522 (ifctx->state == IF_DHCP_OFFERED ||
523 ifctx->state == IF_DHCP_RESOLVED))) &&
524 (bootpc_tag(&gctx->tmptag, &ifctx->reply,
525 ifctx->replylen,
532 bcopy(&gctx->reply, &ifctx->reply, gctx->replylen);
533 ifctx->replylen = gctx->replylen;
536 if (ifctx->state == IF_BOOTP_UNRESOLVED)
537 ifctx->state = IF_BOOTP_RESOLVED;
538 else if (ifctx->state == IF_DHCP_UNRESOLVED &&
539 ifctx->dhcpquerytype == DHCP_DISCOVER) {
541 ifctx->state = IF_DHCP_OFFERED;
543 ifctx->state = IF_BOOTP_RESOLVED; /* Fallback */
544 } else if (ifctx->state == IF_DHCP_OFFERED &&
545 ifctx->dhcpquerytype == DHCP_REQUEST)
546 ifctx->state = IF_DHCP_RESOLVED;
549 if (ifctx->dhcpquerytype == DHCP_DISCOVER &&
550 ifctx->state != IF_BOOTP_RESOLVED) {
551 p = bootpc_tag(&gctx->tmptag, &ifctx->reply,
552 ifctx->replylen, TAG_DHCP_SERVERID);
554 memcpy(&ifctx->dhcpserver, p, 4);
555 ifctx->gotdhcpserver = 1;
557 ifctx->gotdhcpserver = 0;
561 ifctx->gotrootpath = (bootpc_tag(&gctx->tmptag, &ifctx->reply,
562 ifctx->replylen,
564 ifctx->gotgw = (bootpc_tag(&gctx->tmptag, &ifctx->reply,
565 ifctx->replylen,
567 ifctx->gotnetmask = (bootpc_tag(&gctx->tmptag, &ifctx->reply,
568 ifctx->replylen,
584 struct bootpc_ifcontext *ifctx;
660 STAILQ_FOREACH(ifctx, &gctx->interfaces, next) {
661 if (bootpc_ifctx_isresolved(ifctx) != 0 &&
662 bootpc_tag(&gctx->tmptag, &ifctx->reply,
663 ifctx->replylen,
668 STAILQ_FOREACH(ifctx, &gctx->interfaces, next) {
669 struct in_aliasreq *ifra = &ifctx->iareq;
672 ifctx->outstanding = 0;
673 if (bootpc_ifctx_isresolved(ifctx) != 0 &&
677 if (bootpc_ifctx_isfailed(ifctx) != 0)
681 ifctx->outstanding = 1;
684 if ((ifctx->state == IF_DHCP_OFFERED &&
685 ifctx->dhcpquerytype != DHCP_REQUEST) ||
686 (ifctx->state == IF_DHCP_UNRESOLVED &&
687 ifctx->dhcpquerytype != DHCP_DISCOVER) ||
688 (ifctx->state == IF_BOOTP_UNRESOLVED &&
689 ifctx->dhcpquerytype != DHCP_NOMSG)) {
690 ifctx->sentmsg = 0;
691 bootpc_compose_query(ifctx, td);
696 if (ifctx->sentmsg == 0) {
697 switch(ifctx->dhcpquerytype) {
712 ifctx->ireq.ifr_name,
713 ifctx->sdl->sdl_alen,
714 (unsigned char *) LLADDR(ifctx->sdl),
716 ifctx->sentmsg = 1;
719 aio.iov_base = (caddr_t) &ifctx->call;
720 aio.iov_len = sizeof(ifctx->call);
727 auio.uio_resid = sizeof(ifctx->call);
789 STAILQ_FOREACH(ifctx, &gctx->interfaces, next) {
790 if (bootpc_ifctx_isresolved(ifctx) != 0 ||
791 bootpc_ifctx_isfailed(ifctx) != 0)
794 ifctx->call.secs = htons(gctx->secs);
812 STAILQ_FOREACH(ifctx, &gctx->interfaces, next) {
813 if (gctx->reply.xid != ifctx->call.xid)
817 if (gctx->reply.hlen != ifctx->call.hlen)
822 ifctx->call.chaddr,
823 ifctx->call.hlen) != 0)
829 if (ifctx != NULL) {
852 ifctx->ireq.ifr_name);
859 if (bootpc_received(gctx, ifctx) != 0) {
861 if (ifctx->outstanding) {
862 ifctx->outstanding = 0;
871 if (ifctx->gotrootpath ||
876 if (ifctx->gotrootpath)
888 STAILQ_FOREACH(ifctx, &gctx->interfaces, next)
889 if (ifctx->state == IF_DHCP_OFFERED) {
890 if (ifctx->dhcpquerytype == DHCP_DISCOVER)
893 ifctx->state = IF_DHCP_UNRESOLVED;
911 STAILQ_FOREACH(ifctx, &gctx->interfaces, next)
912 if (bootpc_ifctx_isresolved(ifctx) == 0) {
914 ifctx->dhcpquerytype != DHCP_NOMSG ?
916 ifctx->ireq.ifr_name);
927 STAILQ_FOREACH(ifctx, &gctx->interfaces, next)
928 if (bootpc_ifctx_isresolved(ifctx) != 0) {
940 bootpc_fakeup_interface(struct bootpc_ifcontext *ifctx, struct thread *td)
947 ifr = &ifctx->ireq;
948 ifra = &ifctx->iareq;
983 bootpc_shutdown_interface(struct bootpc_ifcontext *ifctx, struct thread *td)
989 ifr = &ifctx->ireq;
991 printf("Shutdown interface %s\n", ifctx->ireq.ifr_name);
1008 bootpc_adjust_interface(struct bootpc_ifcontext *ifctx,
1021 ifr = &ifctx->ireq;
1022 ifra = &ifctx->iareq;
1023 myaddr = &ifctx->myaddr;
1024 netmask = &ifctx->netmask;
1025 gw = &ifctx->gw;
1027 if (bootpc_ifctx_isresolved(ifctx) == 0) {
1029 bootpc_shutdown_interface(ifctx, td);
1033 printf("Adjusted interface %s\n", ifctx->ireq.ifr_name);
1056 if (ifctx->gotgw != 0 || gctx->gotgw == 0) {
1213 bootpc_compose_query(struct bootpc_ifcontext *ifctx, struct thread *td)
1220 ifctx->gotrootpath = 0;
1222 bzero((caddr_t) &ifctx->call, sizeof(ifctx->call));
1225 ifctx->call.op = BOOTP_REQUEST; /* BOOTREQUEST */
1226 ifctx->call.htype = 1; /* 10mb ethernet */
1227 ifctx->call.hlen = ifctx->sdl->sdl_alen;/* Hardware address length */
1228 ifctx->call.hops = 0;
1229 if (bootpc_ifctx_isunresolved(ifctx) != 0)
1230 ifctx->xid++;
1231 ifctx->call.xid = txdr_unsigned(ifctx->xid);
1232 bcopy(LLADDR(ifctx->sdl), &ifctx->call.chaddr, ifctx->sdl->sdl_alen);
1234 vendp = ifctx->call.vend;
1251 ifctx->dhcpquerytype = DHCP_NOMSG;
1252 switch (ifctx->state) {
1257 ifctx->dhcpquerytype = DHCP_DISCOVER;
1258 ifctx->gotdhcpserver = 0;
1264 ifctx->dhcpquerytype = DHCP_REQUEST;
1267 memcpy(vendp, &ifctx->reply.yiaddr, 4);
1269 if (ifctx->gotdhcpserver != 0) {
1272 memcpy(vendp, &ifctx->dhcpserver, 4);
1286 ifctx->call.secs = 0;
1287 ifctx->call.flags = htons(0x8000); /* We need a broadcast answer */
1375 bootpc_decode_reply(struct nfsv3_diskless *nd, struct bootpc_ifcontext *ifctx,
1381 ifctx->gotgw = 0;
1382 ifctx->gotnetmask = 0;
1384 clear_sinaddr(&ifctx->myaddr);
1385 clear_sinaddr(&ifctx->netmask);
1386 clear_sinaddr(&ifctx->gw);
1388 ifctx->myaddr.sin_addr = ifctx->reply.yiaddr;
1390 ip = ntohl(ifctx->myaddr.sin_addr.s_addr);
1392 printf("%s at ", ifctx->ireq.ifr_name);
1393 print_sin_addr(&ifctx->myaddr);
1395 print_in_addr(ifctx->reply.siaddr);
1397 ifctx->gw.sin_addr = ifctx->reply.giaddr;
1398 if (ifctx->reply.giaddr.s_addr != htonl(INADDR_ANY)) {
1400 print_in_addr(ifctx->reply.giaddr);
1405 &ifctx->reply, ifctx->replylen, TAG_END);
1408 if (ifctx->reply.sname[0] != '\0')
1409 printf(" server name %s", ifctx->reply.sname);
1411 if (ifctx->reply.file[0] != '\0')
1412 printf(" boot file %s", ifctx->reply.file);
1416 p = bootpc_tag(&gctx->tag, &ifctx->reply, ifctx->replylen,
1422 bcopy(p, &ifctx->netmask.sin_addr, 4);
1423 ifctx->gotnetmask = 1;
1425 print_sin_addr(&ifctx->netmask);
1429 p = bootpc_tag(&gctx->tag, &ifctx->reply, ifctx->replylen,
1436 bcopy(p, &ifctx->gw.sin_addr, 4);
1438 print_sin_addr(&ifctx->gw);
1440 ifctx->gotgw = 1;
1460 p = bootpc_tag(&gctx->tag, &ifctx->reply, ifctx->replylen,
1473 nd->root_hostnam, p, &ifctx->reply.siaddr)) {
1481 ifctx->gotrootpath = 1;
1482 gctx->setrootfs = ifctx;
1484 p = bootpc_tag(&gctx->tag, &ifctx->reply,
1485 ifctx->replylen,
1495 p = bootpc_tag(&gctx->tag, &ifctx->reply, ifctx->replylen,
1509 gctx->sethostname = ifctx;
1512 p = bootpc_tag(&gctx->tag, &ifctx->reply, ifctx->replylen,
1524 if (ifctx->gotnetmask == 0) {
1525 if (IN_CLASSA(ntohl(ifctx->myaddr.sin_addr.s_addr)))
1526 ifctx->netmask.sin_addr.s_addr = htonl(IN_CLASSA_NET);
1527 else if (IN_CLASSB(ntohl(ifctx->myaddr.sin_addr.s_addr)))
1528 ifctx->netmask.sin_addr.s_addr = htonl(IN_CLASSB_NET);
1530 ifctx->netmask.sin_addr.s_addr = htonl(IN_CLASSC_NET);
1532 if (ifctx->gotgw == 0) {
1534 ifctx->gw.sin_addr.s_addr = ifctx->myaddr.sin_addr.s_addr;
1541 struct bootpc_ifcontext *ifctx; /* Interface BOOTP contexts */
1621 ifctx = STAILQ_FIRST(&gctx->interfaces);
1624 if (ifctx == NULL)
1643 strlcpy(ifctx->ireq.ifr_name, ifp->if_xname,
1644 sizeof(ifctx->ireq.ifr_name));
1645 ifctx->ifp = ifp;
1657 ifctx->ireq.ifr_name);
1658 ifctx->sdl = sdl;
1660 ifctx = STAILQ_NEXT(ifctx, next);
1685 STAILQ_FOREACH(ifctx, &gctx->interfaces, next)
1686 bootpc_fakeup_interface(ifctx, td);
1688 STAILQ_FOREACH(ifctx, &gctx->interfaces, next)
1689 bootpc_compose_query(ifctx, td);
1698 STAILQ_FOREACH(ifctx, &gctx->interfaces, next)
1699 if (bootpc_ifctx_isresolved(ifctx) != 0)
1700 bootpc_decode_reply(nd, ifctx, gctx);
1707 STAILQ_FOREACH(ifctx, &gctx->interfaces, next)
1708 bootpc_adjust_interface(ifctx, gctx, td);
1712 STAILQ_FOREACH(ifctx, &gctx->interfaces, next)
1713 if (ifctx->gotrootpath != 0)
1715 if (ifctx == NULL) {
1716 STAILQ_FOREACH(ifctx, &gctx->interfaces, next)
1717 if (bootpc_ifctx_isresolved(ifctx) != 0)
1720 if (ifctx == NULL)
1725 setenv("boot.netif.name", ifctx->ifp->if_xname);
1743 strcpy(nd->myif.ifra_name, ifctx->ireq.ifr_name);
1744 bcopy(&ifctx->myaddr, &nd->myif.ifra_addr, sizeof(ifctx->myaddr));
1745 bcopy(&ifctx->myaddr, &nd->myif.ifra_broadaddr, sizeof(ifctx->myaddr));
1747 ifctx->myaddr.sin_addr.s_addr |
1748 ~ ifctx->netmask.sin_addr.s_addr;
1749 bcopy(&ifctx->netmask, &nd->myif.ifra_mask, sizeof(ifctx->netmask));
1752 while((ifctx = STAILQ_FIRST(&gctx->interfaces)) != NULL) {
1754 free(ifctx, M_TEMP);