summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReyk Floeter <reyk@cvs.openbsd.org>2009-05-26 08:29:45 +0000
committerReyk Floeter <reyk@cvs.openbsd.org>2009-05-26 08:29:45 +0000
commitf8df2e2ee22841dc7f9536367b570c1dd61b28cc (patch)
treef648d8e09d96fd34efe4c02dd81527f5c57c4720
parent859b06ac4c09e0f8e97b860961881b68307b07d6 (diff)
inherit the route label on cloned routes
ok claudio@
-rw-r--r--sys/net/route.c33
-rw-r--r--sys/net/route.h3
2 files changed, 24 insertions, 12 deletions
diff --git a/sys/net/route.c b/sys/net/route.c
index ae49455f943..bd7861b761b 100644
--- a/sys/net/route.c
+++ b/sys/net/route.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: route.c,v 1.106 2009/05/18 20:37:13 bluhm Exp $ */
+/* $OpenBSD: route.c,v 1.107 2009/05/26 08:29:44 reyk Exp $ */
/* $NetBSD: route.c,v 1.14 1996/02/13 22:00:46 christos Exp $ */
/*
@@ -730,7 +730,7 @@ rtrequest1(int req, struct rt_addrinfo *info, u_int8_t prio,
struct radix_node_head *rnh;
struct ifaddr *ifa;
struct sockaddr *ndst;
- struct sockaddr_rtlabel *sa_rl;
+ struct sockaddr_rtlabel *sa_rl, sa_rl2;
#ifdef MPLS
struct sockaddr_mpls *sa_mpls;
#endif
@@ -815,6 +815,8 @@ rtrequest1(int req, struct rt_addrinfo *info, u_int8_t prio,
info->rti_info[RTAX_GATEWAY] = rt->rt_gateway;
if ((info->rti_info[RTAX_NETMASK] = rt->rt_genmask) == NULL)
info->rti_flags |= RTF_HOST;
+ info->rti_info[RTAX_LABEL] =
+ rtlabel_id2sa(rt->rt_labelid, &sa_rl2);
goto makeroute;
case RTM_ADD:
@@ -1057,7 +1059,6 @@ rtinit(struct ifaddr *ifa, int cmd, int flags)
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) {
@@ -1085,14 +1086,8 @@ rtinit(struct ifaddr *ifa, int cmd, int flags)
info.rti_info[RTAX_DST] = dst;
if (cmd == RTM_ADD)
info.rti_info[RTAX_GATEWAY] = ifa->ifa_addr;
- if (ifa->ifa_ifp->if_rtlabelid &&
- (label = rtlabel_id2name(ifa->ifa_ifp->if_rtlabelid)) != NULL) {
- 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;
- }
+ info.rti_info[RTAX_LABEL] =
+ rtlabel_id2sa(ifa->ifa_ifp->if_rtlabelid, &sa_rl);
/*
* XXX here, it seems that we are assuming that ifa_netmask is NULL
@@ -1398,6 +1393,22 @@ rtlabel_id2name(u_int16_t id)
return (NULL);
}
+struct sockaddr *
+rtlabel_id2sa(u_int16_t labelid, struct sockaddr_rtlabel *sa_rl)
+{
+ const char *label;
+
+ if (labelid == 0 || (label = rtlabel_id2name(labelid)) == NULL)
+ return (NULL);
+
+ 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));
+
+ return ((struct sockaddr *)sa_rl);
+}
+
void
rtlabel_unref(u_int16_t id)
{
diff --git a/sys/net/route.h b/sys/net/route.h
index cb151fdfee3..728ce54a6d6 100644
--- a/sys/net/route.h
+++ b/sys/net/route.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: route.h,v 1.61 2009/05/18 20:37:13 bluhm Exp $ */
+/* $OpenBSD: route.h,v 1.62 2009/05/26 08:29:44 reyk Exp $ */
/* $NetBSD: route.h,v 1.9 1996/02/13 22:00:49 christos Exp $ */
/*
@@ -356,6 +356,7 @@ struct sockaddr_rtlabel {
#ifdef _KERNEL
const char *rtlabel_id2name(u_int16_t);
u_int16_t rtlabel_name2id(char *);
+struct sockaddr *rtlabel_id2sa(u_int16_t, struct sockaddr_rtlabel *);
void rtlabel_unref(u_int16_t);
#define RTFREE(rt) do { \