Index: ifconfig.c =================================================================== RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v retrieving revision 1.434 diff -u -p -r1.434 ifconfig.c --- ifconfig.c 20 Feb 2021 01:17:45 -0000 1.434 +++ ifconfig.c 15 Mar 2021 06:11:51 -0000 @@ -270,6 +270,7 @@ void unsettrunkport(const char *, int); void settrunkproto(const char *, int); void settrunklacpmode(const char *, int); void settrunklacptimeout(const char *, int); +void linkwait(const char *, int); void trunk_status(void); void list_cloners(void); @@ -667,6 +668,7 @@ const struct cmd { { "inst", NEXTARG, A_MEDIAINST, setmediainst }, { "lladdr", NEXTARG, 0, setiflladdr }, { "llprio", NEXTARG, 0, setifllprio }, + { "linkwait", NEXTARG, 0, linkwait }, { NULL, /*src*/ 0, 0, setifaddr }, { NULL, /*dst*/ 0, 0, setifdstaddr }, { NULL, /*illegal*/0, 0, NULL }, @@ -6685,6 +6675,38 @@ setiflladdr(const char *addr, int param) bcopy(eap, ifr.ifr_addr.sa_data, ETHER_ADDR_LEN); if (ioctl(sock, SIOCSIFLLADDR, (caddr_t)&ifr) == -1) warn("SIOCSIFLLADDR"); +} + +void +linkwait(const char *arg, int param) +{ + int waittime; + const char *errstr; + struct if_data ifrdat; + + waittime = strtonum(arg, 1, 120, &errstr); + if (errstr != NULL) + errx(1, "%s wait time %s: %s", ifname, arg, errstr); + + for (;;) { + memset(&ifr, 0, sizeof(ifr)); + memset(&ifrdat, 0, sizeof(ifrdat)); + + strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); + ifr.ifr_data = (caddr_t)&ifrdat; + if (ioctl(sock, SIOCGIFDATA, (caddr_t)&ifr) == -1) + err(1, "%s SIOCGIFDATA", ifname); + + if (LINK_STATE_IS_UP(ifrdat.ifi_link_state)) + return; + + if (waittime-- == 0) + break; + + sleep(1); + } + + errx(1, "%s link wait time expired", ifname); } #ifndef SMALL Index: ifconfig.8 =================================================================== RCS file: /cvs/src/sbin/ifconfig/ifconfig.8,v retrieving revision 1.362 diff -u -p -r1.362 ifconfig.8 --- ifconfig.8 20 Feb 2021 01:21:04 -0000 1.362 +++ ifconfig.8 15 Mar 2021 06:11:51 -0000 @@ -344,6 +344,11 @@ of this is to select the connector type Refer to the man page for the specific driver for more information. .It Cm -link[0-2] Disable special processing at the link level with the specified interface. +.It Cm linkwait Ar seconds +Wait up to the specific number of seconds for the link to come up. +The range of valid +.Ar seconds +values is between 1 and 120. .It Cm lladdr Ar etheraddr Ns | Ns Cm random Change the link layer address (MAC address) of the interface. This should be specified as six colon-separated hex values, or can