summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authormpi <mpi@openbsd.org>2018-06-25 09:41:45 +0000
committermpi <mpi@openbsd.org>2018-06-25 09:41:45 +0000
commit467f284aaeb7bb0f01f00158e9c2ba026f3a8318 (patch)
treea99282dbeb4e16feece51de8bd38bac119763804 /sys
parentPush the NET_LOCK() down in rtm_output(). (diff)
downloadwireguard-openbsd-467f284aaeb7bb0f01f00158e9c2ba026f3a8318.tar.xz
wireguard-openbsd-467f284aaeb7bb0f01f00158e9c2ba026f3a8318.zip
Factorize MPLS setup/teardown into two functions.
ok claudio@
Diffstat (limited to 'sys')
-rw-r--r--sys/net/route.c69
-rw-r--r--sys/net/route.h5
-rw-r--r--sys/net/rtsock.c48
3 files changed, 55 insertions, 67 deletions
diff --git a/sys/net/route.c b/sys/net/route.c
index d80368a41ce..429a52d1b5f 100644
--- a/sys/net/route.c
+++ b/sys/net/route.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: route.c,v 1.375 2018/06/11 08:48:54 mpi Exp $ */
+/* $OpenBSD: route.c,v 1.376 2018/06/25 09:41:45 mpi Exp $ */
/* $NetBSD: route.c,v 1.14 1996/02/13 22:00:46 christos Exp $ */
/*
@@ -518,8 +518,7 @@ rtfree(struct rtentry *rt)
ifafree(rt->rt_ifa);
rtlabel_unref(rt->rt_labelid);
#ifdef MPLS
- if (rt->rt_flags & RTF_MPLS)
- free(rt->rt_llinfo, M_TEMP, sizeof(struct rt_mpls));
+ rt_mpls_clear(rt);
#endif
free(rt->rt_gateway, M_RTABLE, ROUNDUP(rt->rt_gateway->sa_len));
free(rt_key(rt), M_RTABLE, rt_key(rt)->sa_len);
@@ -814,9 +813,6 @@ rtrequest(int req, struct rt_addrinfo *info, u_int8_t prio,
struct sockaddr_rtlabel *sa_rl, sa_rl2;
struct sockaddr_dl sa_dl = { sizeof(sa_dl), AF_LINK };
int dlen, error;
-#ifdef MPLS
- struct sockaddr_mpls *sa_mpls;
-#endif
NET_ASSERT_LOCKED();
@@ -892,32 +888,15 @@ rtrequest(int req, struct rt_addrinfo *info, u_int8_t prio,
if (info->rti_flags & RTF_MPLS &&
(info->rti_info[RTAX_SRC] != NULL ||
info->rti_info[RTAX_DST]->sa_family == AF_MPLS)) {
- struct rt_mpls *rt_mpls;
-
- sa_mpls = (struct sockaddr_mpls *)
- info->rti_info[RTAX_SRC];
-
- rt->rt_llinfo = malloc(sizeof(struct rt_mpls),
- M_TEMP, M_NOWAIT|M_ZERO);
-
- if (rt->rt_llinfo == NULL) {
+ error = rt_mpls_set(rt, info->rti_info[RTAX_SRC],
+ info->rti_mpls);
+ if (error) {
free(ndst, M_RTABLE, dlen);
pool_put(&rtentry_pool, rt);
- return (ENOMEM);
+ return (error);
}
-
- rt_mpls = (struct rt_mpls *)rt->rt_llinfo;
-
- if (sa_mpls != NULL)
- rt_mpls->mpls_label = sa_mpls->smpls_label;
-
- rt_mpls->mpls_operation = info->rti_mpls;
-
- /* XXX: set experimental bits */
-
- rt->rt_flags |= RTF_MPLS;
} else
- rt->rt_flags &= ~RTF_MPLS;
+ rt_mpls_clear(rt);
#endif
ifa->ifa_refcnt++;
@@ -1486,6 +1465,40 @@ rt_timer_timer(void *arg)
timeout_add_sec(to, 1);
}
+#ifdef MPLS
+int
+rt_mpls_set(struct rtentry *rt, struct sockaddr *src, uint8_t op)
+{
+ struct sockaddr_mpls *psa_mpls = (struct sockaddr_mpls *)src;
+ struct rt_mpls *rt_mpls;
+
+ rt->rt_llinfo = malloc(sizeof(struct rt_mpls), M_TEMP, M_NOWAIT|M_ZERO);
+ if (rt->rt_llinfo == NULL)
+ return (ENOMEM);
+
+ rt_mpls = (struct rt_mpls *)rt->rt_llinfo;
+ if (psa_mpls != NULL)
+ rt_mpls->mpls_label = psa_mpls->smpls_label;
+
+ rt_mpls->mpls_operation = op;
+
+ /* XXX: set experimental bits */
+ rt->rt_flags |= RTF_MPLS;
+
+ return (0);
+}
+
+void
+rt_mpls_clear(struct rtentry *rt)
+{
+ if (rt->rt_llinfo != NULL && rt->rt_flags & RTF_MPLS) {
+ free(rt->rt_llinfo, M_TEMP, sizeof(struct rt_mpls));
+ rt->rt_llinfo = NULL;
+ }
+ rt->rt_flags &= ~RTF_MPLS;
+}
+#endif
+
u_int16_t
rtlabel_name2id(char *name)
{
diff --git a/sys/net/route.h b/sys/net/route.h
index 813fd8e5c8e..b9e46030dfa 100644
--- a/sys/net/route.h
+++ b/sys/net/route.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: route.h,v 1.169 2018/04/24 06:19:47 florian Exp $ */
+/* $OpenBSD: route.h,v 1.170 2018/06/25 09:41:45 mpi Exp $ */
/* $NetBSD: route.h,v 1.9 1996/02/13 22:00:49 christos Exp $ */
/*
@@ -442,6 +442,9 @@ void rt_timer_queue_destroy(struct rttimer_queue *);
unsigned long rt_timer_queue_count(struct rttimer_queue *);
void rt_timer_timer(void *);
+int rt_mpls_set(struct rtentry *, struct sockaddr *, uint8_t);
+void rt_mpls_clear(struct rtentry *);
+
int rtisvalid(struct rtentry *);
int rt_hash(struct rtentry *, struct sockaddr *, uint32_t *);
struct rtentry *rtalloc_mpath(struct sockaddr *, uint32_t *, u_int);
diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c
index ed42b94a261..7bdd3ea556d 100644
--- a/sys/net/rtsock.c
+++ b/sys/net/rtsock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rtsock.c,v 1.271 2018/06/25 09:39:16 mpi Exp $ */
+/* $OpenBSD: rtsock.c,v 1.272 2018/06/25 09:41:45 mpi Exp $ */
/* $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $ */
/*
@@ -557,9 +557,6 @@ rtm_report(struct rtentry *rt, u_char type, int seq, int tableid)
#ifdef BFD
struct sockaddr_bfd sa_bfd;
#endif
-#ifdef MPLS
- struct sockaddr_mpls sa_mpls;
-#endif
struct ifnet *ifp = NULL;
int len;
@@ -574,6 +571,8 @@ rtm_report(struct rtentry *rt, u_char type, int seq, int tableid)
#endif
#ifdef MPLS
if (rt->rt_flags & RTF_MPLS) {
+ struct sockaddr_mpls sa_mpls;
+
bzero(&sa_mpls, sizeof(sa_mpls));
sa_mpls.smpls_family = AF_MPLS;
sa_mpls.smpls_len = sizeof(sa_mpls);
@@ -1015,43 +1014,17 @@ change:
#ifdef MPLS
if ((rtm->rtm_flags & RTF_MPLS) &&
info->rti_info[RTAX_SRC] != NULL) {
- struct sockaddr_mpls *psa_mpls;
- struct rt_mpls *rt_mpls;
-
- psa_mpls = (struct sockaddr_mpls *)
- info->rti_info[RTAX_SRC];
-
NET_LOCK();
- if (rt->rt_llinfo == NULL) {
- rt->rt_llinfo =
- malloc(sizeof(struct rt_mpls),
- M_TEMP, M_WAITOK | M_ZERO);
- }
-
- rt_mpls = (struct rt_mpls *)rt->rt_llinfo;
-
- if (psa_mpls != NULL) {
- rt_mpls->mpls_label =
- psa_mpls->smpls_label;
- }
-
- rt_mpls->mpls_operation = info->rti_mpls;
-
- /* XXX: set experimental bits */
-
- rt->rt_flags |= RTF_MPLS;
+ error = rt_mpls_set(rt,
+ info->rti_info[RTAX_SRC], info->rti_mpls);
NET_UNLOCK();
+ if (error)
+ break;
} else if (newgate || ((rtm->rtm_fmask & RTF_MPLS) &&
!(rtm->rtm_flags & RTF_MPLS))) {
NET_LOCK();
/* if gateway changed remove MPLS information */
- if (rt->rt_llinfo != NULL &&
- rt->rt_flags & RTF_MPLS) {
- free(rt->rt_llinfo, M_TEMP,
- sizeof(struct rt_mpls));
- rt->rt_llinfo = NULL;
- rt->rt_flags &= ~RTF_MPLS;
- }
+ rt_mpls_clear(rt);
NET_UNLOCK();
}
#endif
@@ -1654,9 +1627,6 @@ sysctl_dumpentry(struct rtentry *rt, void *v, unsigned int id)
#ifdef BFD
struct sockaddr_bfd sa_bfd;
#endif
-#ifdef MPLS
- struct sockaddr_mpls sa_mpls;
-#endif
struct sockaddr_rtlabel sa_rl;
struct sockaddr_in6 sa_mask;
@@ -1694,6 +1664,8 @@ sysctl_dumpentry(struct rtentry *rt, void *v, unsigned int id)
#endif
#ifdef MPLS
if (rt->rt_flags & RTF_MPLS) {
+ struct sockaddr_mpls sa_mpls;
+
bzero(&sa_mpls, sizeof(sa_mpls));
sa_mpls.smpls_family = AF_MPLS;
sa_mpls.smpls_len = sizeof(sa_mpls);