jcs's openbsd hax
openbsd
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

change dhcpd to use the rdomain/rtable it was started in.

previously it would use the rdomain on the first interface it was
explicitly configured to open. it is much more natural to use the rdomain it's been started in, which integrates better with rcctl.

a version of this was tested by mark patruck
ok kn@ claudio@

dlg 45347ff3 9c529f57

+75 -89
+6 -7
usr.sbin/dhcpd/dhcpd.c
··· 1 - /* $OpenBSD: dhcpd.c,v 1.61 2025/06/04 21:16:25 dlg Exp $ */ 1 + /* $OpenBSD: dhcpd.c,v 1.62 2025/06/10 06:29:53 dlg Exp $ */ 2 2 3 3 /* 4 4 * Copyright (c) 2004 Henning Brauer <henning@cvs.openbsd.org> ··· 71 71 u_int16_t server_port; 72 72 u_int16_t client_port; 73 73 74 + int rdomain; 74 75 struct passwd *pw; 75 76 int log_priority; 76 77 int pfpipe[2]; ··· 87 88 int 88 89 main(int argc, char *argv[]) 89 90 { 90 - int ch, cftest = 0, rdomain = -1, udpsockmode = 0; 91 + int ch, cftest = 0, udpsockmode = 0; 91 92 int debug = 0, verbose = 0; 92 93 char *sync_iface = NULL; 93 94 char *sync_baddr = NULL; ··· 97 98 98 99 log_init(1, LOG_DAEMON); /* log to stderr until daemonized */ 99 100 log_setverbose(1); 101 + 102 + rdomain = getrtable(); 100 103 101 104 opterr = 0; 102 105 while ((ch = getopt(argc, argv, "A:C:L:c:dfl:nu::vY:y:")) != -1) ··· 197 200 198 201 db_startup(); 199 202 if (!udpsockmode || argc > 0) 200 - discover_interfaces(&rdomain); 201 - 202 - if (rdomain != -1) 203 - if (setrtable(rdomain) == -1) 204 - fatal("setrtable"); 203 + discover_interfaces(); 205 204 206 205 if (syncsend || syncrecv) { 207 206 if (sync_init(sync_iface, sync_baddr, sync_port) == -1)
+2 -2
usr.sbin/dhcpd/dhcpd.h
··· 1 - /* $OpenBSD: dhcpd.h,v 1.72 2025/05/31 07:47:45 dlg Exp $ */ 1 + /* $OpenBSD: dhcpd.h,v 1.73 2025/06/10 06:29:53 dlg Exp $ */ 2 2 3 3 /* 4 4 * Copyright (c) 1995, 1996, 1997, 1998, 1999 ··· 443 443 extern struct interface_info *interfaces; 444 444 extern struct protocol *protocols; 445 445 extern struct dhcpd_timeout *timeouts; 446 - void discover_interfaces(int *); 446 + void discover_interfaces(void); 447 447 void dispatch(void); 448 448 int locate_network(struct packet *); 449 449 void got_one(struct protocol *);
+67 -80
usr.sbin/dhcpd/dispatch.c
··· 1 - /* $OpenBSD: dispatch.c,v 1.49 2025/06/04 21:16:25 dlg Exp $ */ 1 + /* $OpenBSD: dispatch.c,v 1.50 2025/06/10 06:29:53 dlg Exp $ */ 2 2 3 3 /* 4 4 * Copyright (c) 1995, 1996, 1997, 1998, 1999 ··· 67 67 #include "log.h" 68 68 #include "sync.h" 69 69 70 + extern int rdomain; 71 + 70 72 struct interface_info *interfaces; 71 73 struct protocol *protocols; 72 74 struct dhcpd_timeout *timeouts; ··· 81 83 subnet it's on, and add it to the list of interfaces. */ 82 84 83 85 void 84 - discover_interfaces(int *rdomain) 86 + discover_interfaces(void) 85 87 { 86 88 struct interface_info *tmp; 87 89 struct interface_info *last, *next; 88 90 struct subnet *subnet; 89 91 struct shared_network *share; 90 92 struct sockaddr_in foo; 91 - int ir = 0, ird; 93 + int ir; 92 94 struct ifreq *tif; 93 95 struct ifaddrs *ifap, *ifa; 94 96 ··· 99 101 * If we already have a list of interfaces, the interfaces were 100 102 * requested. 101 103 */ 102 - if (interfaces != NULL) 103 - ir = 1; 104 - else 105 - /* must specify an interface when rdomains are used */ 106 - *rdomain = 0; 104 + ir = (interfaces != NULL); 107 105 108 106 /* Cycle through the list of interfaces looking for IP addresses. */ 109 107 for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) { ··· 125 123 if (tmp == NULL && ir) 126 124 continue; 127 125 128 - ird = get_rdomain(ifa->ifa_name); 129 - if (*rdomain == -1) 130 - *rdomain = ird; 131 - else if (*rdomain != ird && ir) 132 - fatalx("Interface %s is not in rdomain %d", 133 - tmp->name, *rdomain); 134 - else if (*rdomain != ird && !ir) 135 - continue; 136 - 137 126 /* If there isn't already an interface by this name, 138 127 allocate one. */ 139 128 if (tmp == NULL) { ··· 150 139 /* If we have the capability, extract link information 151 140 and record it in a linked list. */ 152 141 if (ifa->ifa_addr->sa_family == AF_LINK) { 153 - struct sockaddr_dl *sdl = 154 - ((struct sockaddr_dl *)(ifa->ifa_addr)); 142 + struct if_data *ifi = ifa->ifa_data; 143 + struct sockaddr_dl *sdl; 144 + 145 + if (rdomain != ifi->ifi_rdomain) 146 + continue; 147 + 148 + sdl = (struct sockaddr_dl *)ifa->ifa_addr; 155 149 tmp->index = sdl->sdl_index; 156 150 tmp->hw_address.hlen = sdl->sdl_alen; 157 151 tmp->hw_address.htype = HTYPE_ETHER; /* XXX */ 158 152 memcpy(tmp->hw_address.haddr, 159 153 LLADDR(sdl), sdl->sdl_alen); 160 154 } else if (ifa->ifa_addr->sa_family == AF_INET) { 161 - struct iaddr addr; 162 - 163 155 /* Get a pointer to the address... */ 164 156 memcpy(&foo, ifa->ifa_addr, sizeof(foo)); 165 157 ··· 182 174 tmp->ifp = tif; 183 175 tmp->primary_address = foo.sin_addr; 184 176 } 185 - 186 - /* Grab the address... */ 187 - addr.len = 4; 188 - memcpy(addr.iabuf, &foo.sin_addr.s_addr, addr.len); 189 - 190 - /* If there's a registered subnet for this address, 191 - connect it together... */ 192 - if ((subnet = find_subnet(addr))) { 193 - /* If this interface has multiple aliases 194 - on the same subnet, ignore all but the 195 - first we encounter. */ 196 - if (!subnet->interface) { 197 - subnet->interface = tmp; 198 - subnet->interface_address = addr; 199 - } else if (subnet->interface != tmp) { 200 - log_warnx("Multiple %s %s: %s %s", 201 - "interfaces match the", 202 - "same subnet", 203 - subnet->interface->name, 204 - tmp->name); 205 - } 206 - share = subnet->shared_network; 207 - if (tmp->shared_network && 208 - tmp->shared_network != share) { 209 - log_warnx("Interface %s matches %s", 210 - tmp->name, 211 - "multiple shared networks"); 212 - } else { 213 - tmp->shared_network = share; 214 - } 215 - 216 - if (!share->interface) { 217 - share->interface = tmp; 218 - } else if (share->interface != tmp) { 219 - log_warnx("Multiple %s %s: %s %s", 220 - "interfaces match the", 221 - "same shared network", 222 - share->interface->name, 223 - tmp->name); 224 - } 225 - } 226 177 } 227 178 } 228 179 229 180 /* Discard interfaces we can't listen on. */ 230 181 last = NULL; 231 182 for (tmp = interfaces; tmp; tmp = next) { 183 + struct iaddr addr; 184 + 232 185 next = tmp->next; 233 186 187 + if (tmp->index == 0) { 188 + log_warnx("Can't listen on %s - wrong rdomain", 189 + tmp->name); 190 + /* Remove tmp from the list of interfaces. */ 191 + if (!last) 192 + interfaces = interfaces->next; 193 + else 194 + last->next = tmp->next; 195 + continue; 196 + } 197 + 234 198 if (!tmp->ifp) { 235 199 log_warnx("Can't listen on %s - it has no IP address.", 236 200 tmp->name); ··· 243 207 } 244 208 245 209 memcpy(&foo, &tmp->ifp->ifr_addr, sizeof tmp->ifp->ifr_addr); 210 + 211 + /* Grab the address... */ 212 + addr.len = 4; 213 + memcpy(addr.iabuf, &foo.sin_addr.s_addr, addr.len); 214 + 215 + /* If there's a registered subnet for this address, 216 + connect it together... */ 217 + if ((subnet = find_subnet(addr))) { 218 + /* If this interface has multiple aliases 219 + on the same subnet, ignore all but the 220 + first we encounter. */ 221 + if (!subnet->interface) { 222 + subnet->interface = tmp; 223 + subnet->interface_address = addr; 224 + } else if (subnet->interface != tmp) { 225 + log_warnx("Multiple %s %s: %s %s", 226 + "interfaces match the", 227 + "same subnet", 228 + subnet->interface->name, 229 + tmp->name); 230 + } 231 + share = subnet->shared_network; 232 + if (tmp->shared_network && 233 + tmp->shared_network != share) { 234 + log_warnx("Interface %s matches %s", 235 + tmp->name, 236 + "multiple shared networks"); 237 + } else { 238 + tmp->shared_network = share; 239 + } 240 + 241 + if (!share->interface) { 242 + share->interface = tmp; 243 + } else if (share->interface != tmp) { 244 + log_warnx("Multiple %s %s: %s %s", 245 + "interfaces match the", 246 + "same shared network", 247 + share->interface->name, 248 + tmp->name); 249 + } 250 + } 246 251 247 252 if (!tmp->shared_network) { 248 253 log_warnx("Can't listen on %s - dhcpd.conf has no " ··· 617 622 } 618 623 } 619 624 } 620 - 621 - int 622 - get_rdomain(char *name) 623 - { 624 - int rv = 0, s; 625 - struct ifreq ifr; 626 - 627 - if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1) 628 - fatal("get_rdomain socket"); 629 - 630 - memset(&ifr, 0, sizeof(ifr)); 631 - strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); 632 - if (ioctl(s, SIOCGIFRDOMAIN, (caddr_t)&ifr) != -1) 633 - rv = ifr.ifr_rdomainid; 634 - 635 - close(s); 636 - return rv; 637 - }