summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorReyk Floeter <reyk@cvs.openbsd.org>2007-06-14 18:31:51 +0000
committerReyk Floeter <reyk@cvs.openbsd.org>2007-06-14 18:31:51 +0000
commitdc5624a00a4b3e598c4818940cc0904e9f2742bd (patch)
treeb9c40d324900c98391c1224812e1861094cf2909 /sys
parentd20ad6759bbb32d01503007c7d2101018d380551 (diff)
Add a new "rtlabel" option to ifconfig. It allows to specify a route label
which will be used for new interface routes. For example, ifconfig em0 10.1.1.0 255.255.255.0 rtlabel RING_1 will set the new interface address and attach the route label RING_1 to the corresponding route. manpage bits from jmc@ ok claudio@ henning@
Diffstat (limited to 'sys')
-rw-r--r--sys/net/if.c22
-rw-r--r--sys/net/if.h3
-rw-r--r--sys/net/route.c13
-rw-r--r--sys/sys/sockio.h5
4 files changed, 39 insertions, 4 deletions
diff --git a/sys/net/if.c b/sys/net/if.c
index 0852b5c425b..322437c670e 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if.c,v 1.161 2007/06/08 09:31:38 henning Exp $ */
+/* $OpenBSD: if.c,v 1.162 2007/06/14 18:31:49 reyk Exp $ */
/* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */
/*
@@ -1151,9 +1151,11 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct proc *p)
struct sockaddr_dl *sdl;
struct ifgroupreq *ifgr;
char ifdescrbuf[IFDESCRSIZE];
+ char ifrtlabelbuf[RTLABEL_LEN];
int error = 0;
size_t bytesdone;
short oif_flags;
+ const char *label;
switch (cmd) {
@@ -1291,6 +1293,24 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct proc *p)
}
break;
+ case SIOCGIFRTLABEL:
+ label = rtlabel_id2name(ifp->if_rtlabelid);
+ strlcpy(ifrtlabelbuf, label, RTLABEL_LEN);
+ error = copyoutstr(ifrtlabelbuf, ifr->ifr_data, RTLABEL_LEN,
+ &bytesdone);
+ break;
+
+ case SIOCSIFRTLABEL:
+ if ((error = suser(p, 0)) != 0)
+ return (error);
+ error = copyinstr(ifr->ifr_data, ifrtlabelbuf,
+ RTLABEL_LEN, &bytesdone);
+ if (error == 0) {
+ rtlabel_unref(ifp->if_rtlabelid);
+ ifp->if_rtlabelid = rtlabel_name2id(ifrtlabelbuf);
+ }
+ break;
+
case SIOCAIFGROUP:
if ((error = suser(p, 0)))
return (error);
diff --git a/sys/net/if.h b/sys/net/if.h
index 4b3c56542b0..13b976aed93 100644
--- a/sys/net/if.h
+++ b/sys/net/if.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: if.h,v 1.89 2007/05/29 18:18:57 uwe Exp $ */
+/* $OpenBSD: if.h,v 1.90 2007/06/14 18:31:49 reyk Exp $ */
/* $NetBSD: if.h,v 1.23 1996/05/07 02:40:27 thorpej Exp $ */
/*
@@ -200,6 +200,7 @@ struct ifnet { /* and the entries */
u_int32_t if_hardmtu; /* maximum MTU device supports */
int if_capabilities; /* interface capabilities */
char if_description[IFDESCRSIZE]; /* interface description */
+ u_short if_rtlabelid; /* next route label */
/* procedure handles */
/* output routine (enqueue) */
diff --git a/sys/net/route.c b/sys/net/route.c
index b469c4468b6..0005e2c0b74 100644
--- a/sys/net/route.c
+++ b/sys/net/route.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: route.c,v 1.83 2007/05/08 20:57:19 claudio Exp $ */
+/* $OpenBSD: route.c,v 1.84 2007/06/14 18:31:49 reyk Exp $ */
/* $NetBSD: route.c,v 1.14 1996/02/13 22:00:46 christos Exp $ */
/*
@@ -1003,6 +1003,8 @@ rtinit(struct ifaddr *ifa, int cmd, int flags)
struct rtentry *nrt = NULL;
int error;
struct rt_addrinfo info;
+ struct sockaddr_rtlabel sa_rl;
+ const char *label;
dst = flags & RTF_HOST ? ifa->ifa_dstaddr : ifa->ifa_addr;
if (cmd == RTM_DELETE) {
@@ -1029,6 +1031,15 @@ rtinit(struct ifaddr *ifa, int cmd, int flags)
info.rti_flags = flags | ifa->ifa_flags;
info.rti_info[RTAX_DST] = dst;
info.rti_info[RTAX_GATEWAY] = ifa->ifa_addr;
+ if (ifa->ifa_ifp->if_rtlabelid) {
+ label = rtlabel_id2name(ifa->ifa_ifp->if_rtlabelid);
+ bzero(&sa_rl, sizeof(sa_rl));
+ sa_rl.sr_len = sizeof(sa_rl);
+ sa_rl.sr_family = AF_UNSPEC;
+ strlcpy(sa_rl.sr_label, label, sizeof(sa_rl.sr_label));
+ info.rti_info[RTAX_LABEL] = (struct sockaddr *)&sa_rl;
+ }
+
/*
* XXX here, it seems that we are assuming that ifa_netmask is NULL
* for RTF_HOST. bsdi4 passes NULL explicitly (via intermediate
diff --git a/sys/sys/sockio.h b/sys/sys/sockio.h
index 80f8f58b09a..64d6d587bc4 100644
--- a/sys/sys/sockio.h
+++ b/sys/sys/sockio.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: sockio.h,v 1.38 2006/12/03 13:41:19 reyk Exp $ */
+/* $OpenBSD: sockio.h,v 1.39 2007/06/14 18:31:50 reyk Exp $ */
/* $NetBSD: sockio.h,v 1.5 1995/08/23 00:40:47 thorpej Exp $ */
/*-
@@ -155,6 +155,9 @@
#define SIOCSIFDESCR _IOW('i', 128, struct ifreq) /* set ifnet descr */
#define SIOCGIFDESCR _IOWR('i', 129, struct ifreq) /* get ifnet descr */
+#define SIOCSIFRTLABEL _IOW('i', 130, struct ifreq) /* set ifnet rtlabel */
+#define SIOCGIFRTLABEL _IOWR('i', 131, struct ifreq) /* set ifnet rtlabel */
+
#define SIOCSIFTIMESLOT _IOW('i', 133, struct ifreq) /* set ifnet timeslot */
#define SIOCGIFTIMESLOT _IOWR('i', 134, struct ifreq) /* get ifnet timeslot */