Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/net Refactor gif_set_tunnel(). No functional change.
details: https://anonhg.NetBSD.org/src/rev/632a7de89b9d
branches: trunk
changeset: 342148:632a7de89b9d
user: knakahara <knakahara%NetBSD.org@localhost>
date: Wed Dec 09 03:33:32 2015 +0000
description:
Refactor gif_set_tunnel(). No functional change.
diffstat:
sys/net/if_gif.c | 103 +++++++++++++++++++++++++++++++++---------------------
1 files changed, 62 insertions(+), 41 deletions(-)
diffs (152 lines):
diff -r c93de51fc183 -r 632a7de89b9d sys/net/if_gif.c
--- a/sys/net/if_gif.c Wed Dec 09 03:31:28 2015 +0000
+++ b/sys/net/if_gif.c Wed Dec 09 03:33:32 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_gif.c,v 1.96 2015/12/09 03:31:28 knakahara Exp $ */
+/* $NetBSD: if_gif.c,v 1.97 2015/12/09 03:33:32 knakahara Exp $ */
/* $KAME: if_gif.c,v 1.76 2001/08/20 02:01:02 kjc Exp $ */
/*
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.96 2015/12/09 03:31:28 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.97 2015/12/09 03:33:32 knakahara Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -96,6 +96,9 @@
static int gif_clone_destroy(struct ifnet *);
static int gif_check_nesting(struct ifnet *, struct mbuf *);
+static int gif_encap_attach(struct gif_softc *);
+static int gif_encap_detach(struct gif_softc *);
+
static struct if_clone gif_cloner =
IF_CLONE_INITIALIZER("gif", gif_clone_create, gif_clone_destroy);
@@ -677,6 +680,60 @@
return error;
}
+static int
+gif_encap_attach(struct gif_softc *sc)
+{
+ int error;
+
+ if (sc == NULL || sc->gif_psrc == NULL)
+ return EINVAL;
+
+ switch (sc->gif_psrc->sa_family) {
+#ifdef INET
+ case AF_INET:
+ error = in_gif_attach(sc);
+ break;
+#endif
+#ifdef INET6
+ case AF_INET6:
+ error = in6_gif_attach(sc);
+ break;
+#endif
+ default:
+ error = EINVAL;
+ break;
+ }
+
+ return error;
+}
+
+static int
+gif_encap_detach(struct gif_softc *sc)
+{
+ int error;
+
+ if (sc == NULL || sc->gif_psrc == NULL)
+ return EINVAL;
+
+ switch (sc->gif_psrc->sa_family) {
+#ifdef INET
+ case AF_INET:
+ error = in_gif_detach(sc);
+ break;
+#endif
+#ifdef INET6
+ case AF_INET6:
+ error = in6_gif_detach(sc);
+ break;
+#endif
+ default:
+ error = EINVAL;
+ break;
+ }
+
+ return error;
+}
+
int
gif_set_tunnel(struct ifnet *ifp, struct sockaddr *src, struct sockaddr *dst)
{
@@ -722,18 +779,7 @@
}
/* XXX we can detach from both, but be polite just in case */
if (sc->gif_psrc)
- switch (sc->gif_psrc->sa_family) {
-#ifdef INET
- case AF_INET:
- (void)in_gif_detach(sc);
- break;
-#endif
-#ifdef INET6
- case AF_INET6:
- (void)in6_gif_detach(sc);
- break;
-#endif
- }
+ (void)gif_encap_detach(sc);
/*
* Secondly, try to set new configurations.
@@ -745,21 +791,7 @@
sc->gif_psrc = nsrc;
sc->gif_pdst = ndst;
- switch (sc->gif_psrc->sa_family) {
-#ifdef INET
- case AF_INET:
- error = in_gif_attach(sc);
- break;
-#endif
-#ifdef INET6
- case AF_INET6:
- error = in6_gif_attach(sc);
- break;
-#endif
- default:
- error = EINVAL;
- break;
- }
+ error = gif_encap_attach(sc);
if (error) {
/* rollback to the last configuration. */
nsrc = osrc;
@@ -772,18 +804,7 @@
sc->gif_si = softint_establish(SOFTINT_NET, gifintr, sc);
if (sc->gif_si == NULL) {
- switch (sc->gif_psrc->sa_family) {
-#ifdef INET
- case AF_INET:
- (void)in_gif_detach(sc);
- break;
-#endif
-#ifdef INET6
- case AF_INET6:
- (void)in6_gif_detach(sc);
- break;
-#endif
- }
+ (void)gif_encap_detach(sc);
/* rollback to the last configuration. */
nsrc = osrc;
Home |
Main Index |
Thread Index |
Old Index