-/* $OpenBSD: dhclient.c,v 1.464 2017/07/10 00:47:47 krw Exp $ */
+/* $OpenBSD: dhclient.c,v 1.465 2017/07/10 14:11:47 krw Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
int addressinuse(char *, struct in_addr, char *);
void fork_privchld(struct interface_info *, int, int);
-void get_ifname(struct interface_info *, char *);
+void get_ifname(struct interface_info *, int, char *);
struct client_lease *apply_defaults(struct client_lease *);
struct client_lease *clone_lease(struct client_lease *);
ifi = calloc(1, sizeof(struct interface_info));
if (ifi == NULL)
fatalx("ifi calloc");
- get_ifname(ifi, argv[0]);
+ if ((ioctlfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
+ fatal("Can't create socket to do ioctl");
+ get_ifname(ifi, ioctlfd, argv[0]);
ifi->index = if_nametoindex(ifi->name);
if (ifi->index == 0)
fatalx("%s: no such interface", ifi->name);
tzset();
/* Get the ssid if present. */
- if ((ioctlfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
- fatalx("Can't create socket to do ioctl");
memset(&ifr, 0, sizeof(ifr));
memset(&nwid, 0, sizeof(nwid));
ifr.ifr_data = (caddr_t)&nwid;
}
void
-get_ifname(struct interface_info *ifi, char *arg)
+get_ifname(struct interface_info *ifi, int ioctlfd, char *arg)
{
struct ifgroupreq ifgr;
struct ifg_req *ifg;
unsigned int len;
- int s;
if (strcmp(arg, "egress") == 0) {
- s = socket(AF_INET, SOCK_DGRAM, 0);
- if (s == -1)
- fatalx("socket error");
memset(&ifgr, 0, sizeof(ifgr));
strlcpy(ifgr.ifgr_name, "egress", sizeof(ifgr.ifgr_name));
- if (ioctl(s, SIOCGIFGMEMB, (caddr_t)&ifgr) == -1) {
+ if (ioctl(ioctlfd, SIOCGIFGMEMB, (caddr_t)&ifgr) == -1) {
if (errno == ENOENT)
fatalx("no interface in group egress found");
fatal("ioctl SIOCGIFGMEMB");
len = ifgr.ifgr_len;
if ((ifgr.ifgr_groups = calloc(1, len)) == NULL)
fatalx("get_ifname");
- if (ioctl(s, SIOCGIFGMEMB, (caddr_t)&ifgr) == -1)
+ if (ioctl(ioctlfd, SIOCGIFGMEMB, (caddr_t)&ifgr) == -1)
fatal("ioctl SIOCGIFGMEMB");
arg = NULL;
fatal("Interface name too long");
free(ifgr.ifgr_groups);
- close(s);
} else if (strlcpy(ifi->name, arg, IFNAMSIZ) >= IFNAMSIZ)
fatalx("Interface name too long");
}
-/* $OpenBSD: kroute.c,v 1.106 2017/07/10 00:47:47 krw Exp $ */
+/* $OpenBSD: kroute.c,v 1.107 2017/07/10 14:11:47 krw Exp $ */
/*
* Copyright 2012 Kenneth R Westerback <krw@openbsd.org>
}
void
-priv_add_route(int rdomain, struct imsg_add_route *imsg)
+priv_add_route(int rdomain, int routefd, struct imsg_add_route *imsg)
{
char destbuf[INET_ADDRSTRLEN];
char gatewaybuf[INET_ADDRSTRLEN];
struct rt_msghdr rtm;
struct sockaddr_in dest, gateway, mask, ifa;
struct sockaddr_rtlabel label;
- int s, i, iovcnt = 0;
-
- if ((s = socket(AF_ROUTE, SOCK_RAW, 0)) == -1)
- fatal("Routing Socket open failed");
+ int i, iovcnt = 0;
memset(destbuf, 0, sizeof(destbuf));
memset(maskbuf, 0, sizeof(maskbuf));
/* Check for EEXIST since other dhclient may not be done. */
for (i = 0; i < 5; i++) {
- if (writev(s, iov, iovcnt) != -1)
+ if (writev(routefd, iov, iovcnt) != -1)
break;
if (i == 4)
log_warn("failed to add route (%s/%s via %s/%s)",
else if (errno == EEXIST || errno == ENETUNREACH)
sleep(1);
}
-
- close(s);
}
/*
-/* $OpenBSD: privsep.h,v 1.43 2017/07/08 00:36:10 krw Exp $ */
+/* $OpenBSD: privsep.h,v 1.44 2017/07/10 14:11:47 krw Exp $ */
/*
* Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
void add_default_route(struct in_addr, struct in_addr);
void add_static_routes(struct option_data *, struct in_addr);
void add_classless_static_routes(struct option_data *, struct in_addr);
-void priv_add_route(int, struct imsg_add_route *);
+void priv_add_route(int, int, struct imsg_add_route *);
void priv_flush_routes(char *, int, int);
char *resolv_conf_contents(char *, struct option_data *,