Hello again, ok and while i did the patches i'm replying to, i did't understand: the code seems to be a real nifty automatic deduction of configuration data which is made available somewhere else (ifconfig(8)).
It may be stupid, useless etc. The appended diff implements a '=GROUPNAME' command line argument syntax, and thus allows to freely specify groups. What do you think of that? --steffen diff --git a/sbin/dhclient/dhclient.8 b/sbin/dhclient/dhclient.8 index 9d77c7e..b6094c1 100644 --- a/sbin/dhclient/dhclient.8 +++ b/sbin/dhclient/dhclient.8 @@ -57,6 +57,16 @@ The name of the network interface that .Nm should attempt to configure must be specified on the command line. +If the given name starts with the character +.Cm = , +then +.Nm +will treat the remaining characters as the name of a group defined by +.Xr ifconfig 8 , +and try to use the interface which is marked in that group. +See +.Xr ifconfig 8 +for more on groups. .Pp The options are as follows: .Bl -tag -width "-p port" @@ -169,7 +179,8 @@ database of acquired leases .Xr dhclient-script 8 , .Xr dhcp 8 , .Xr dhcpd 8 , -.Xr dhcrelay 8 +.Xr dhcrelay 8 , +.Xr ifconfig 8 .Sh AUTHORS .An -nosplit .Nm diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index 8d35021..fa0cbef 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -2077,37 +2077,47 @@ get_ifname(char *ifname, char *arg) struct ifg_req *ifg; int s, len; - if (!strcmp(arg, "egress")) { - s = socket(AF_INET, SOCK_DGRAM, 0); - if (s == -1) - error("socket error"); - bzero(&ifgr, sizeof(ifgr)); - strlcpy(ifgr.ifgr_name, "egress", sizeof(ifgr.ifgr_name)); - if (ioctl(s, SIOCGIFGMEMB, (caddr_t)&ifgr) == -1) { - if (errno == ENOENT) - error("no interface in group egress found"); - error("ioctl SIOCGIFGMEMB: %m"); - } - len = ifgr.ifgr_len; - if ((ifgr.ifgr_groups = calloc(1, len)) == NULL) - error("get_ifname"); - if (ioctl(s, SIOCGIFGMEMB, (caddr_t)&ifgr) == -1) - error("ioctl SIOCGIFGMEMB: %m"); - - arg = NULL; - for (ifg = ifgr.ifgr_groups; - ifg && len >= sizeof(struct ifg_req); ifg++) { - len -= sizeof(struct ifg_req); - if (arg) - error("too many interfaces in group egress"); - arg = ifg->ifgrq_member; - } - + s = (*arg == '='); + if (s) + ++arg; + /* 'egress' for compatibility with 4.9 */ + else if (strcmp(arg, "egress")) { if (strlcpy(ifi->name, arg, IFNAMSIZ) >= IFNAMSIZ) - error("Interface name too long: %m"); + error("Interface name too long"); + return (0); + } + + /* Try deduce interface from if */ + s = socket(AF_INET, SOCK_DGRAM, 0); + if (s == -1) + error("socket error"); + bzero(&ifgr, sizeof(ifgr)); - free(ifgr.ifgr_groups); - close(s); - } else if (strlcpy(ifi->name, arg, IFNAMSIZ) >= IFNAMSIZ) + if (strlcpy(ifgr.ifgr_name, arg, IFNAMSIZ) >= IFNAMSIZ) error("Interface name too long"); + + if (ioctl(s, SIOCGIFGMEMB, (caddr_t)&ifgr) == -1) { + if (errno == ENOENT) + error("no interface in group %s found", arg); + error("ioctl SIOCGIFGMEMB: %m"); + } + len = ifgr.ifgr_len; + if ((ifgr.ifgr_groups = calloc(1, len)) == NULL) + error("get_ifname"); + if (ioctl(s, SIOCGIFGMEMB, (caddr_t)&ifgr) == -1) + error("ioctl SIOCGIFGMEMB: %m"); + + arg = NULL; + for (ifg = ifgr.ifgr_groups; + ifg && len >= sizeof(struct ifg_req); ifg++) { + len -= sizeof(struct ifg_req); + if (arg) + error("too many interfaces in group %s", arg); + arg = ifg->ifgrq_member; + } + + (void)strlcpy(ifi->name, arg, IFNAMSIZ); + + free(ifgr.ifgr_groups); + close(s); }