summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormichele <michele@openbsd.org>2009-01-08 12:47:45 +0000
committermichele <michele@openbsd.org>2009-01-08 12:47:45 +0000
commit13a1ade2440eb2bf8235673673400632a56b8396 (patch)
tree98e119be11a62530c3256997f7d18c9421eeaa8d
parentFull stub area support. This allows ABRs to announce a default network (diff)
downloadwireguard-openbsd-13a1ade2440eb2bf8235673673400632a56b8396.tar.xz
wireguard-openbsd-13a1ade2440eb2bf8235673673400632a56b8396.zip
Fix sockaddr_mpls structure.
Now it contains just the label as it must be. This introduces a ugly hack in rtentry that will be removed as soon as possible. OK claudio@
-rw-r--r--sys/net/route.c17
-rw-r--r--sys/net/route.h6
-rw-r--r--sys/net/rtsock.c36
-rw-r--r--sys/netmpls/mpls.h9
-rw-r--r--sys/netmpls/mpls_input.c34
-rw-r--r--sys/netmpls/mpls_output.c25
-rw-r--r--sys/netmpls/mpls_proto.c4
-rw-r--r--sys/netmpls/mpls_shim.c4
8 files changed, 98 insertions, 37 deletions
diff --git a/sys/net/route.c b/sys/net/route.c
index 3baafe32598..74c274cb772 100644
--- a/sys/net/route.c
+++ b/sys/net/route.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: route.c,v 1.100 2008/12/12 22:07:33 claudio Exp $ */
+/* $OpenBSD: route.c,v 1.101 2009/01/08 12:47:45 michele Exp $ */
/* $NetBSD: route.c,v 1.14 1996/02/13 22:00:46 christos Exp $ */
/*
@@ -121,6 +121,10 @@
#include <netinet/in.h>
#include <netinet/in_var.h>
+#ifdef MPLS
+#include <netmpls/mpls.h>
+#endif
+
#ifdef IPSEC
#include <netinet/ip_ipsp.h>
#include <net/if_enc.h>
@@ -723,6 +727,9 @@ rtrequest1(int req, struct rt_addrinfo *info, u_int8_t prio,
struct ifaddr *ifa;
struct sockaddr *ndst;
struct sockaddr_rtlabel *sa_rl;
+#ifdef MPLS
+ struct sockaddr_mpls *sa_mpls;
+#endif
#define senderr(x) { error = x ; goto bad; }
if ((rnh = rt_gettable(info->rti_info[RTAX_DST]->sa_family, tableid)) ==
@@ -859,6 +866,14 @@ makeroute:
rt->rt_labelid = rtlabel_name2id(sa_rl->sr_label);
}
+#ifdef MPLS
+ if (info->rti_info[RTAX_SRC] != NULL) {
+ sa_mpls = (struct sockaddr_mpls *)
+ info->rti_info[RTAX_SRC];
+ rt->rt_mpls = sa_mpls->smpls_label;
+ }
+#endif
+
ifa->ifa_refcnt++;
rt->rt_ifa = ifa;
rt->rt_ifp = ifa->ifa_ifp;
diff --git a/sys/net/route.h b/sys/net/route.h
index e6385e93100..3ce2f803fba 100644
--- a/sys/net/route.h
+++ b/sys/net/route.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: route.h,v 1.55 2008/12/12 22:07:33 claudio Exp $ */
+/* $OpenBSD: route.h,v 1.56 2009/01/08 12:47:45 michele Exp $ */
/* $NetBSD: route.h,v 1.9 1996/02/13 22:00:49 christos Exp $ */
/*
@@ -121,6 +121,10 @@ struct rtentry {
LIST_HEAD(, rttimer) rt_timer; /* queue of timeouts for misc funcs */
u_int16_t rt_labelid; /* route label ID */
u_int8_t rt_priority; /* routing priority to use */
+#ifdef MPLS
+ /* XXX: temporay hack, will be removed soon */
+ u_int32_t rt_mpls; /* MPLS outbound label */
+#endif
};
#define rt_use rt_rmx.rmx_pksent
diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c
index 60752027e7a..7d830e5e40c 100644
--- a/sys/net/rtsock.c
+++ b/sys/net/rtsock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rtsock.c,v 1.80 2009/01/03 15:31:03 claudio Exp $ */
+/* $OpenBSD: rtsock.c,v 1.81 2009/01/08 12:47:45 michele Exp $ */
/* $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $ */
/*
@@ -183,6 +183,10 @@ route_output(struct mbuf *m, ...)
struct socket *so;
struct rawcb *rp = NULL;
struct sockaddr_rtlabel sa_rt;
+#ifdef MPLS
+ struct sockaddr_mpls sa_mpls;
+ struct sockaddr_mpls *psa_mpls;
+#endif
const char *label;
va_list ap;
u_int tableid;
@@ -421,7 +425,16 @@ report:
info.rti_info[RTAX_LABEL] =
(struct sockaddr *)&sa_rt;
}
-
+#ifdef MPLS
+ if (rt->rt_mpls) {
+ bzero(&sa_mpls, sizeof(sa_mpls));
+ sa_mpls.smpls_family = AF_MPLS;
+ sa_mpls.smpls_len = sizeof(sa_mpls);
+ sa_mpls.smpls_label = rt->rt_mpls;
+ info.rti_info[RTAX_SRC] =
+ (struct sockaddr *)&sa_mpls;
+ }
+#endif
ifpaddr = 0;
ifaaddr = 0;
if (rtm->rtm_addrs & (RTA_IFP | RTA_IFA) &&
@@ -509,6 +522,13 @@ report:
rt->rt_labelid =
rtlabel_name2id(rtlabel);
}
+#ifdef MPLS
+ if (info.rti_info[RTAX_SRC] != NULL) {
+ psa_mpls = (struct sockaddr_mpls *)
+ info.rti_info[RTAX_SRC];
+ rt->rt_mpls = psa_mpls->smpls_label;
+ }
+#endif
if_group_routechange(dst, netmask);
/* FALLTHROUGH */
case RTM_LOCK:
@@ -922,6 +942,9 @@ sysctl_dumpentry(struct radix_node *rn, void *v)
struct rtentry *rt = (struct rtentry *)rn;
int error = 0, size;
struct rt_addrinfo info;
+#ifdef MPLS
+ struct sockaddr_mpls sa_mpls;
+#endif
struct sockaddr_rtlabel sa_rt;
const char *label;
@@ -949,6 +972,15 @@ sysctl_dumpentry(struct radix_node *rn, void *v)
(struct sockaddr *)&sa_rt;
}
}
+#ifdef MPLS
+ if (rt->rt_mpls) {
+ bzero(&sa_mpls, sizeof(sa_mpls));
+ sa_mpls.smpls_family = AF_MPLS;
+ sa_mpls.smpls_len = sizeof(sa_mpls);
+ sa_mpls.smpls_label = rt->rt_mpls;
+ info.rti_info[RTAX_SRC] = (struct sockaddr *)&sa_mpls;
+ }
+#endif
size = rt_msg2(RTM_GET, RTM_VERSION, &info, NULL, w);
if (w->w_where && w->w_tmem && w->w_needed <= 0) {
diff --git a/sys/netmpls/mpls.h b/sys/netmpls/mpls.h
index 1553a538945..f89151248bb 100644
--- a/sys/netmpls/mpls.h
+++ b/sys/netmpls/mpls.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mpls.h,v 1.15 2008/12/15 16:13:55 michele Exp $ */
+/* $OpenBSD: mpls.h,v 1.16 2009/01/08 12:47:45 michele Exp $ */
/*
* Copyright (C) 1999, 2000 and 2001 AYAME Project, WIDE Project.
@@ -50,6 +50,8 @@ struct shim_hdr {
u_int32_t shim_label; /* 20 bit label, 4 bit exp & BoS, 8 bit TTL */
};
+#define MPLS_HDRLEN sizeof(struct shim_hdr)
+
/*
* By byte-swapping the constants, we avoid ever having to byte-swap IP
* addresses inside the kernel. Unfortunately, user-level programs rely
@@ -87,8 +89,9 @@ struct shim_hdr {
struct sockaddr_mpls {
u_int8_t smpls_len; /* length */
u_int8_t smpls_family; /* AF_MPLS */
- u_int32_t smpls_out_label; /* outgoing MPLS label */
- u_int32_t smpls_in_label; /* MPLS label 20 bits*/
+ u_int16_t smpls_pad0;
+ u_int32_t smpls_label; /* MPLS label */
+ u_int32_t smpls_pad1[2];
};
#define MPLS_OP_POP RTF_PROTO1
diff --git a/sys/netmpls/mpls_input.c b/sys/netmpls/mpls_input.c
index 5df12744427..9382aa6f9cb 100644
--- a/sys/netmpls/mpls_input.c
+++ b/sys/netmpls/mpls_input.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mpls_input.c,v 1.16 2008/12/15 16:13:55 michele Exp $ */
+/* $OpenBSD: mpls_input.c,v 1.17 2009/01/08 12:47:45 michele Exp $ */
/*
* Copyright (c) 2008 Claudio Jeker <claudio@openbsd.org>
@@ -70,7 +70,8 @@ mpls_input(struct mbuf *m)
{
struct ifnet *ifp = m->m_pkthdr.rcvif;
struct sockaddr_mpls *smpls;
- struct sockaddr_mpls sa_mpls;
+ struct sockaddr_mpls *newsmpls;
+ struct sockaddr_mpls sa_mpls, sa_outmpls;
struct shim_hdr *shim;
struct rtentry *rt = NULL;
u_int8_t ttl;
@@ -91,6 +92,11 @@ mpls_input(struct mbuf *m)
if ((m = m_pullup(m, sizeof(*shim))) == NULL)
return;
+ bzero(&sa_outmpls, sizeof(sa_outmpls));
+ newsmpls = &sa_outmpls;
+ newsmpls->smpls_family = AF_MPLS;
+ newsmpls->smpls_len = sizeof(*smpls);
+
shim = mtod(m, struct shim_hdr *);
#ifdef MPLS_DEBUG
@@ -118,22 +124,22 @@ mpls_input(struct mbuf *m)
smpls = &sa_mpls;
smpls->smpls_family = AF_MPLS;
smpls->smpls_len = sizeof(*smpls);
- smpls->smpls_in_label = shim->shim_label & MPLS_LABEL_MASK;
+ smpls->smpls_label = shim->shim_label & MPLS_LABEL_MASK;
#ifdef MPLS_DEBUG
printf("smpls af %d len %d in_label %d in_ifindex %d\n",
smpls->smpls_family, smpls->smpls_len,
- MPLS_LABEL_GET(smpls->smpls_in_label),
+ MPLS_LABEL_GET(smpls->smpls_label),
ifp->if_index);
#endif
- if (ntohl(smpls->smpls_in_label) < MPLS_LABEL_RESERVED_MAX) {
+ if (ntohl(smpls->smpls_label) < MPLS_LABEL_RESERVED_MAX) {
hasbos = MPLS_BOS_ISSET(shim->shim_label);
m = mpls_shim_pop(m);
shim = mtod(m, struct shim_hdr *);
- switch (ntohl(smpls->smpls_in_label)) {
+ switch (ntohl(smpls->smpls_label)) {
case MPLS_LABEL_IPV4NULL:
if (hasbos) {
@@ -165,13 +171,7 @@ mpls_input(struct mbuf *m)
rt->rt_use++;
smpls = satosmpls(rt_key(rt));
-
-#ifdef MPLS_DEBUG
- printf("route af %d len %d in_label %d in_ifindex %d\n",
- smpls->smpls_family, smpls->smpls_len,
- MPLS_LABEL_GET(smpls->smpls_in_label),
- ifp->if_index);
-#endif
+ newsmpls->smpls_label = rt->rt_mpls;
switch (rt->rt_flags & (MPLS_OP_PUSH | MPLS_OP_POP |
MPLS_OP_SWAP)){
@@ -192,10 +192,10 @@ mpls_input(struct mbuf *m)
}
break;
case MPLS_OP_PUSH:
- m = mpls_shim_push(m, smpls);
+ m = mpls_shim_push(m, newsmpls);
break;
case MPLS_OP_SWAP:
- m = mpls_shim_swap(m, smpls);
+ m = mpls_shim_swap(m, newsmpls);
break;
default:
m_freem(m);
@@ -222,8 +222,8 @@ mpls_input(struct mbuf *m)
#ifdef MPLS_DEBUG
printf("MPLS: sending on %s outlabel %x dst af %d in %d out %d\n",
ifp->if_xname, ntohl(shim->shim_label), smpls->smpls_family,
- MPLS_LABEL_GET(smpls->smpls_in_label),
- MPLS_LABEL_GET(smpls->smpls_out_label));
+ MPLS_LABEL_GET(smpls->smpls_label),
+ MPLS_LABEL_GET(newsmpls->smpls_label));
#endif
(*ifp->if_output)(ifp, m, smplstosa(smpls), rt);
diff --git a/sys/netmpls/mpls_output.c b/sys/netmpls/mpls_output.c
index 03591baa0e6..c8f16019444 100644
--- a/sys/netmpls/mpls_output.c
+++ b/sys/netmpls/mpls_output.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mpls_output.c,v 1.3 2008/12/15 16:13:55 michele Exp $ */
+/* $OpenBSD: mpls_output.c,v 1.4 2009/01/08 12:47:45 michele Exp $ */
/*
* Copyright (c) 2008 Claudio Jeker <claudio@openbsd.org>
@@ -38,7 +38,8 @@ mpls_output(struct mbuf *m)
{
struct ifnet *ifp = m->m_pkthdr.rcvif;
struct sockaddr_mpls *smpls;
- struct sockaddr_mpls sa_mpls;
+ struct sockaddr_mpls *newsmpls;
+ struct sockaddr_mpls sa_mpls, sa_outmpls;
struct shim_hdr *shim;
struct rtentry *rt = NULL;
u_int32_t ttl;
@@ -56,6 +57,11 @@ mpls_output(struct mbuf *m)
if ((m = m_pullup(m, sizeof(*shim))) == NULL)
return;
+ bzero(&sa_outmpls, sizeof(sa_outmpls));
+ newsmpls = &sa_outmpls;
+ newsmpls->smpls_family = AF_MPLS;
+ newsmpls->smpls_len = sizeof(*smpls);
+
shim = mtod(m, struct shim_hdr *);
/* extract TTL */
@@ -66,12 +72,12 @@ mpls_output(struct mbuf *m)
smpls = &sa_mpls;
smpls->smpls_family = AF_MPLS;
smpls->smpls_len = sizeof(*smpls);
- smpls->smpls_in_label = shim->shim_label & MPLS_LABEL_MASK;
+ smpls->smpls_label = shim->shim_label & MPLS_LABEL_MASK;
#ifdef MPLS_DEBUG
printf("smpls af %d len %d in_label %d in_ifindex %d\n",
smpls->smpls_family, smpls->smpls_len,
- MPLS_LABEL_GET(smpls->smpls_in_label),
+ MPLS_LABEL_GET(smpls->smpls_label),
ifp->if_index);
#endif
@@ -88,11 +94,12 @@ mpls_output(struct mbuf *m)
rt->rt_use++;
smpls = satosmpls(rt_key(rt));
+ newsmpls->smpls_label = rt->rt_mpls;
#ifdef MPLS_DEBUG
printf("route af %d len %d in_label %d in_ifindex %d\n",
smpls->smpls_family, smpls->smpls_len,
- MPLS_LABEL_GET(smpls->smpls_in_label),
+ MPLS_LABEL_GET(smpls->smpls_label),
ifp->if_index);
#endif
@@ -109,10 +116,10 @@ mpls_output(struct mbuf *m)
m = mpls_shim_pop(m);
break;
case MPLS_OP_PUSH:
- m = mpls_shim_push(m, smpls);
+ m = mpls_shim_push(m, newsmpls);
break;
case MPLS_OP_SWAP:
- m = mpls_shim_swap(m, smpls);
+ m = mpls_shim_swap(m, newsmpls);
break;
default:
m_freem(m);
@@ -139,8 +146,8 @@ mpls_output(struct mbuf *m)
#ifdef MPLS_DEBUG
printf("MPLS: sending on %s outlabel %x dst af %d in %d out %d\n",
ifp->if_xname, ntohl(shim->shim_label), smpls->smpls_family,
- MPLS_LABEL_GET(smpls->smpls_in_label),
- MPLS_LABEL_GET(smpls->smpls_out_label));
+ MPLS_LABEL_GET(smpls->smpls_label),
+ MPLS_LABEL_GET(smpls->smpls_label));
#endif
(*ifp->if_output)(ifp, m, smplstosa(smpls), rt);
diff --git a/sys/netmpls/mpls_proto.c b/sys/netmpls/mpls_proto.c
index d2e987ca0df..a2ddb5979c2 100644
--- a/sys/netmpls/mpls_proto.c
+++ b/sys/netmpls/mpls_proto.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mpls_proto.c,v 1.3 2008/12/15 16:13:55 michele Exp $ */
+/* $OpenBSD: mpls_proto.c,v 1.4 2009/01/08 12:47:45 michele Exp $ */
/*
* Copyright (C) 1999, 2000 and 2001 AYAME Project, WIDE Project.
@@ -71,6 +71,6 @@ struct domain mplsdomain = {
mplssw,
&mplssw[sizeof(mplssw)/sizeof(mplssw[0])], 0,
rn_inithead,
- offsetof(struct sockaddr_mpls, smpls_in_label) << 3,
+ offsetof(struct sockaddr_mpls, smpls_label) << 3,
sizeof(struct sockaddr_mpls)
};
diff --git a/sys/netmpls/mpls_shim.c b/sys/netmpls/mpls_shim.c
index 4152dd07da2..32c27713236 100644
--- a/sys/netmpls/mpls_shim.c
+++ b/sys/netmpls/mpls_shim.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mpls_shim.c,v 1.4 2008/12/15 16:13:55 michele Exp $ */
+/* $OpenBSD: mpls_shim.c,v 1.5 2009/01/08 12:47:45 michele Exp $ */
/*
* Copyright (C) 1999, 2000 and 2001 AYAME Project, WIDE Project.
@@ -70,7 +70,7 @@ mpls_shim_swap(struct mbuf *m, struct sockaddr_mpls *smplsp)
/* swap label */
shim->shim_label &= ~MPLS_LABEL_MASK;
- shim->shim_label |= smplsp->smpls_out_label & MPLS_LABEL_MASK;
+ shim->shim_label |= smplsp->smpls_label & MPLS_LABEL_MASK;
/* swap exp : XXX exp override */
{