summaryrefslogtreecommitdiff
path: root/sys/net
diff options
context:
space:
mode:
authorHenning Brauer <henning@cvs.openbsd.org>2018-09-09 10:09:07 +0000
committerHenning Brauer <henning@cvs.openbsd.org>2018-09-09 10:09:07 +0000
commitbe7f4d8a3c8b34ab0eb6d01d66fd22ff7c522f1a (patch)
tree57251c851e14435c428b27712ac9e598df39d93a /sys/net
parent53b596e31ca38f87d7b578400a54d559a2f34e53 (diff)
if_setrdomain: allow empty rtables to be turned into rdomains, not just
nonexistant ones as before. nasty error handling with bluhm, feedback mpi as well. ok bluhm
Diffstat (limited to 'sys/net')
-rw-r--r--sys/net/if.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/sys/net/if.c b/sys/net/if.c
index a78b53db9bc..0a6c4157ff9 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if.c,v 1.560 2018/09/08 01:03:59 yasuoka Exp $ */
+/* $OpenBSD: if.c,v 1.561 2018/09/09 10:09:06 henning Exp $ */
/* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */
/*
@@ -1738,7 +1738,7 @@ int
if_setrdomain(struct ifnet *ifp, int rdomain)
{
struct ifreq ifr;
- int error, up = 0, s;
+ int error, createerr, up = 0, s;
if (rdomain < 0 || rdomain > RT_TABLEID_MAX)
return (EINVAL);
@@ -1752,28 +1752,29 @@ if_setrdomain(struct ifnet *ifp, int rdomain)
* Create the routing table if it does not exist, including its
* loopback interface with unit == rdomain.
*/
- if (!rtable_exists(rdomain)) {
+ if (!rtable_exists(rdomain) || rtable_empty(rdomain)) {
struct ifnet *loifp;
char loifname[IFNAMSIZ];
unsigned int unit = rdomain;
snprintf(loifname, sizeof(loifname), "lo%u", unit);
- error = if_clone_create(loifname, 0);
+ createerr = if_clone_create(loifname, 0);
+ if (createerr && createerr != EEXIST)
+ return (createerr);
if ((loifp = ifunit(loifname)) == NULL)
return (ENXIO);
- /* Do not error out if creating the default lo(4) interface */
- if (error && (ifp != loifp || error != EEXIST))
- return (error);
-
- if ((error = rtable_add(rdomain)) == 0)
- rtable_l2set(rdomain, rdomain, loifp->if_index);
- if (error) {
- if_clone_destroy(loifname);
- return (error);
+ if (!rtable_exists(rdomain)) {
+ error = rtable_add(rdomain);
+ if (error) {
+ if (createerr != EEXIST)
+ if_clone_destroy(loifname);
+ return (error);
+ }
}
+ rtable_l2set(rdomain, rdomain, loifp->if_index);
loifp->if_rdomain = rdomain;
}