diff options
author | Reyk Floeter <reyk@cvs.openbsd.org> | 2007-06-14 18:31:51 +0000 |
---|---|---|
committer | Reyk Floeter <reyk@cvs.openbsd.org> | 2007-06-14 18:31:51 +0000 |
commit | dc5624a00a4b3e598c4818940cc0904e9f2742bd (patch) | |
tree | b9c40d324900c98391c1224812e1861094cf2909 | |
parent | d20ad6759bbb32d01503007c7d2101018d380551 (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@
-rw-r--r-- | sbin/ifconfig/ifconfig.8 | 17 | ||||
-rw-r--r-- | sbin/ifconfig/ifconfig.c | 18 | ||||
-rw-r--r-- | sys/net/if.c | 22 | ||||
-rw-r--r-- | sys/net/if.h | 3 | ||||
-rw-r--r-- | sys/net/route.c | 13 | ||||
-rw-r--r-- | sys/sys/sockio.h | 5 |
6 files changed, 71 insertions, 7 deletions
diff --git a/sbin/ifconfig/ifconfig.8 b/sbin/ifconfig/ifconfig.8 index d248cf8c5d3..702038683d6 100644 --- a/sbin/ifconfig/ifconfig.8 +++ b/sbin/ifconfig/ifconfig.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ifconfig.8,v 1.144 2007/06/13 06:46:26 henning Exp $ +.\" $OpenBSD: ifconfig.8,v 1.145 2007/06/14 18:31:50 reyk Exp $ .\" $NetBSD: ifconfig.8,v 1.11 1996/01/04 21:27:29 pk Exp $ .\" $FreeBSD: ifconfig.8,v 1.16 1998/02/01 07:03:29 steve Exp $ .\" @@ -31,7 +31,7 @@ .\" .\" @(#)ifconfig.8 8.4 (Berkeley) 6/1/94 .\" -.Dd $Mdocdate: June 13 2007 $ +.Dd $Mdocdate: June 14 2007 $ .Dt IFCONFIG 8 .Os .Sh NAME @@ -385,6 +385,19 @@ AppleTalk uses this scheme instead of netmasks though .Ox implements it internally as a set of netmasks. +.It Cm rtlabel Ar route-label +(inet) +Attach +.Ar route-label +to new network routes of the specified interface. +Route labels can be used to implement policy routing; +see +.Xr route 4 , +.Xr route 8 , +and +.Xr pf.conf 5 . +.It Cm -rtlabel +Clear the route label. .It Cm timeslot Ar timeslot_range Set the timeslot range map, which is used to control which channels an interface device uses. diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index a7eb7ac3d95..8f13ea8b423 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ifconfig.c,v 1.180 2007/06/13 06:46:26 henning Exp $ */ +/* $OpenBSD: ifconfig.c,v 1.181 2007/06/14 18:31:50 reyk Exp $ */ /* $NetBSD: ifconfig.c,v 1.40 1997/10/01 02:19:43 enami Exp $ */ /* @@ -140,6 +140,7 @@ void notrailers(const char *, int); void setifgroup(const char *, int); void unsetifgroup(const char *, int); void setifaddr(const char *, int); +void setifrtlabel(const char *, int); void setiflladdr(const char *, int); void setifdstaddr(const char *, int); void setifflags(const char *, int); @@ -298,6 +299,8 @@ const struct cmd { { "eui64", 0, 0, setia6eui64 }, #endif /*INET6*/ #ifndef SMALL + { "rtlabel", NEXTARG, 0, setifrtlabel }, + { "-rtlabel", -1, 0, setifrtlabel }, { "range", NEXTARG, 0, setatrange }, { "phase", NEXTARG, 0, setatphase }, { "vlan", NEXTARG, 0, setvlantag }, @@ -940,6 +943,19 @@ setifaddr(const char *addr, int param) (*afp->af_getaddr)(addr, (doalias >= 0 ? ADDR : RIDADDR)); } +#ifndef SMALL +void +setifrtlabel(const char *label, int d) +{ + if (d != 0) + ifr.ifr_data = (caddr_t)(const char *)""; + else + ifr.ifr_data = (caddr_t)label; + if (ioctl(s, SIOCSIFRTLABEL, &ifr) < 0) + warn("SIOCSIFRTLABEL"); +} +#endif + /* ARGSUSED */ void setifnetmask(const char *addr, int ignored) 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 */ |