Module Name: src
Committed By: ozaki-r
Date: Mon Apr 27 02:59:44 UTC 2015
Modified Files:
src/sys/netinet: dccp_usrreq.c tcp_input.c tcp_output.c tcp_subr.c
src/sys/netinet6: in6_pcb.c in6_pcb.h in6_src.c udp6_output.c
Log Message:
Introduce in6_selecthlim_rt to consolidate an idiom for rt->rt_ifp
It consolidates a scattered routine:
(rt = rtcache_validate(&in6p->in6p_route)) != NULL ? rt->rt_ifp : NULL
To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/netinet/dccp_usrreq.c
cvs rdiff -u -r1.337 -r1.338 src/sys/netinet/tcp_input.c
cvs rdiff -u -r1.180 -r1.181 src/sys/netinet/tcp_output.c
cvs rdiff -u -r1.259 -r1.260 src/sys/netinet/tcp_subr.c
cvs rdiff -u -r1.137 -r1.138 src/sys/netinet6/in6_pcb.c
cvs rdiff -u -r1.43 -r1.44 src/sys/netinet6/in6_pcb.h
cvs rdiff -u -r1.56 -r1.57 src/sys/netinet6/in6_src.c
cvs rdiff -u -r1.47 -r1.48 src/sys/netinet6/udp6_output.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/netinet/dccp_usrreq.c
diff -u src/sys/netinet/dccp_usrreq.c:1.4 src/sys/netinet/dccp_usrreq.c:1.5
--- src/sys/netinet/dccp_usrreq.c:1.4 Sun Apr 26 21:40:49 2015
+++ src/sys/netinet/dccp_usrreq.c Mon Apr 27 02:59:44 2015
@@ -1,5 +1,5 @@
/* $KAME: dccp_usrreq.c,v 1.67 2005/11/03 16:05:04 nishida Exp $ */
-/* $NetBSD: dccp_usrreq.c,v 1.4 2015/04/26 21:40:49 rtr Exp $ */
+/* $NetBSD: dccp_usrreq.c,v 1.5 2015/04/27 02:59:44 ozaki-r Exp $ */
/*
* Copyright (c) 2003 Joacim H�ggmark, Magnus Erixzon, Nils-Erik Mattsson
@@ -67,7 +67,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dccp_usrreq.c,v 1.4 2015/04/26 21:40:49 rtr Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dccp_usrreq.c,v 1.5 2015/04/27 02:59:44 ozaki-r Exp $");
#include "opt_inet.h"
#include "opt_dccp.h"
@@ -91,7 +91,6 @@ __KERNEL_RCSID(0, "$NetBSD: dccp_usrreq.
#include <sys/queue.h>
#include <net/if.h>
-#include <net/route.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
@@ -2308,9 +2307,6 @@ dccp_newdccpcb(int family, void *aux)
struct inpcb *inp;
struct in6pcb *in6p;
struct dccpcb *dp;
-#ifdef INET6
- struct rtentry *rt;
-#endif
DCCP_DEBUG((LOG_INFO, "Creating a new dccpcb!\n"));
@@ -2362,8 +2358,7 @@ dccp_newdccpcb(int family, void *aux)
case PF_INET6:
in6p = (struct in6pcb *)aux;
dp->d_in6pcb = in6p;
- rt = rtcache_validate(&in6p->in6p_route);
- in6p->in6p_ip6.ip6_hlim = in6_selecthlim(in6p, (rt != NULL) ? rt->rt_ifp : NULL);
+ in6p->in6p_ip6.ip6_hlim = in6_selecthlim_rt(in6p);
in6p->in6p_ppcb = dp;
break;
}
Index: src/sys/netinet/tcp_input.c
diff -u src/sys/netinet/tcp_input.c:1.337 src/sys/netinet/tcp_input.c:1.338
--- src/sys/netinet/tcp_input.c:1.337 Sat Mar 14 02:08:16 2015
+++ src/sys/netinet/tcp_input.c Mon Apr 27 02:59:44 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: tcp_input.c,v 1.337 2015/03/14 02:08:16 rtr Exp $ */
+/* $NetBSD: tcp_input.c,v 1.338 2015/04/27 02:59:44 ozaki-r Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -148,7 +148,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.337 2015/03/14 02:08:16 rtr Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.338 2015/04/27 02:59:44 ozaki-r Exp $");
#include "opt_inet.h"
#include "opt_ipsec.h"
@@ -174,7 +174,6 @@ __KERNEL_RCSID(0, "$NetBSD: tcp_input.c,
#include <sys/cprng.h>
#include <net/if.h>
-#include <net/route.h>
#include <net/if_types.h>
#include <netinet/in.h>
@@ -4797,8 +4796,7 @@ syn_cache_respond(struct syn_cache *sc,
#ifdef INET6
case AF_INET6:
ip6->ip6_hlim = in6_selecthlim(NULL,
- (rt = rtcache_validate(ro)) != NULL ? rt->rt_ifp
- : NULL);
+ (rt = rtcache_validate(ro)) != NULL ? rt->rt_ifp : NULL);
error = ip6_output(m, NULL /*XXX*/, ro, 0, NULL, so, NULL);
break;
Index: src/sys/netinet/tcp_output.c
diff -u src/sys/netinet/tcp_output.c:1.180 src/sys/netinet/tcp_output.c:1.181
--- src/sys/netinet/tcp_output.c:1.180 Sat Feb 14 12:57:53 2015
+++ src/sys/netinet/tcp_output.c Mon Apr 27 02:59:44 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: tcp_output.c,v 1.180 2015/02/14 12:57:53 he Exp $ */
+/* $NetBSD: tcp_output.c,v 1.181 2015/04/27 02:59:44 ozaki-r Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -135,7 +135,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tcp_output.c,v 1.180 2015/02/14 12:57:53 he Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_output.c,v 1.181 2015/04/27 02:59:44 ozaki-r Exp $");
#include "opt_inet.h"
#include "opt_ipsec.h"
@@ -1579,9 +1579,7 @@ timer:
* setsockopt. Also, desired default hop limit might
* be changed via Neighbor Discovery.
*/
- ip6->ip6_hlim = in6_selecthlim(tp->t_in6pcb,
- (rt = rtcache_validate(ro)) != NULL ? rt->rt_ifp
- : NULL);
+ ip6->ip6_hlim = in6_selecthlim_rt(tp->t_in6pcb);
}
ip6->ip6_flow |= htonl(ecn_tos << 20);
/* ip6->ip6_flow = ??? (from template) */
Index: src/sys/netinet/tcp_subr.c
diff -u src/sys/netinet/tcp_subr.c:1.259 src/sys/netinet/tcp_subr.c:1.260
--- src/sys/netinet/tcp_subr.c:1.259 Mon Apr 13 15:51:00 2015
+++ src/sys/netinet/tcp_subr.c Mon Apr 27 02:59:44 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: tcp_subr.c,v 1.259 2015/04/13 15:51:00 riastradh Exp $ */
+/* $NetBSD: tcp_subr.c,v 1.260 2015/04/27 02:59:44 ozaki-r Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.259 2015/04/13 15:51:00 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.260 2015/04/27 02:59:44 ozaki-r Exp $");
#include "opt_inet.h"
#include "opt_ipsec.h"
@@ -637,9 +637,6 @@ int
tcp_respond(struct tcpcb *tp, struct mbuf *mtemplate, struct mbuf *m,
struct tcphdr *th0, tcp_seq ack, tcp_seq seq, int flags)
{
-#ifdef INET6
- struct rtentry *rt;
-#endif
struct route *ro;
int error, tlen, win = 0;
int hlen;
@@ -878,13 +875,9 @@ tcp_respond(struct tcpcb *tp, struct mbu
th->th_sum = in6_cksum(m, IPPROTO_TCP, sizeof(struct ip6_hdr),
tlen);
ip6->ip6_plen = htons(tlen);
- if (tp && tp->t_in6pcb) {
- struct ifnet *oifp;
- ro = &tp->t_in6pcb->in6p_route;
- oifp = (rt = rtcache_validate(ro)) != NULL ? rt->rt_ifp
- : NULL;
- ip6->ip6_hlim = in6_selecthlim(tp->t_in6pcb, oifp);
- } else
+ if (tp && tp->t_in6pcb)
+ ip6->ip6_hlim = in6_selecthlim_rt(tp->t_in6pcb);
+ else
ip6->ip6_hlim = ip6_defhlim;
ip6->ip6_flow &= ~IPV6_FLOWINFO_MASK;
if (ip6_auto_flowlabel) {
@@ -1035,9 +1028,6 @@ tcp_tcpcb_template(void)
struct tcpcb *
tcp_newtcpcb(int family, void *aux)
{
-#ifdef INET6
- struct rtentry *rt;
-#endif
struct tcpcb *tp;
int i;
@@ -1076,10 +1066,7 @@ tcp_newtcpcb(int family, void *aux)
{
struct in6pcb *in6p = (struct in6pcb *)aux;
- in6p->in6p_ip6.ip6_hlim = in6_selecthlim(in6p,
- (rt = rtcache_validate(&in6p->in6p_route)) != NULL
- ? rt->rt_ifp
- : NULL);
+ in6p->in6p_ip6.ip6_hlim = in6_selecthlim_rt(in6p);
in6p->in6p_ppcb = (void *)tp;
tp->t_in6pcb = in6p;
Index: src/sys/netinet6/in6_pcb.c
diff -u src/sys/netinet6/in6_pcb.c:1.137 src/sys/netinet6/in6_pcb.c:1.138
--- src/sys/netinet6/in6_pcb.c:1.137 Sun Apr 26 16:45:50 2015
+++ src/sys/netinet6/in6_pcb.c Mon Apr 27 02:59:44 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: in6_pcb.c,v 1.137 2015/04/26 16:45:50 rtr Exp $ */
+/* $NetBSD: in6_pcb.c,v 1.138 2015/04/27 02:59:44 ozaki-r Exp $ */
/* $KAME: in6_pcb.c,v 1.84 2001/02/08 18:02:08 itojun Exp $ */
/*
@@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in6_pcb.c,v 1.137 2015/04/26 16:45:50 rtr Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6_pcb.c,v 1.138 2015/04/27 02:59:44 ozaki-r Exp $");
#include "opt_inet.h"
#include "opt_ipsec.h"
@@ -426,7 +426,6 @@ in6_pcbbind(void *v, struct sockaddr_in6
int
in6_pcbconnect(void *v, struct mbuf *nam, struct lwp *l)
{
- struct rtentry *rt;
struct in6pcb *in6p = v;
struct in6_addr *in6a = NULL;
struct sockaddr_in6 *sin6 = mtod(nam, struct sockaddr_in6 *);
@@ -526,10 +525,11 @@ in6_pcbconnect(void *v, struct mbuf *nam
return (error);
}
}
- if (ifp == NULL && (rt = rtcache_validate(&in6p->in6p_route)) != NULL)
- ifp = rt->rt_ifp;
- in6p->in6p_ip6.ip6_hlim = (u_int8_t)in6_selecthlim(in6p, ifp);
+ if (ifp != NULL)
+ in6p->in6p_ip6.ip6_hlim = (u_int8_t)in6_selecthlim(in6p, ifp);
+ else
+ in6p->in6p_ip6.ip6_hlim = (u_int8_t)in6_selecthlim_rt(in6p);
if (in6_pcblookup_connect(in6p->in6p_table, &sin6->sin6_addr,
sin6->sin6_port,
Index: src/sys/netinet6/in6_pcb.h
diff -u src/sys/netinet6/in6_pcb.h:1.43 src/sys/netinet6/in6_pcb.h:1.44
--- src/sys/netinet6/in6_pcb.h:1.43 Fri Apr 24 22:32:37 2015
+++ src/sys/netinet6/in6_pcb.h Mon Apr 27 02:59:44 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: in6_pcb.h,v 1.43 2015/04/24 22:32:37 rtr Exp $ */
+/* $NetBSD: in6_pcb.h,v 1.44 2015/04/27 02:59:44 ozaki-r Exp $ */
/* $KAME: in6_pcb.h,v 1.45 2001/02/09 05:59:46 itojun Exp $ */
/*
@@ -174,6 +174,7 @@ void in6_setsockaddr(struct in6pcb *, st
/* in in6_src.c */
int in6_selecthlim(struct in6pcb *, struct ifnet *);
+int in6_selecthlim_rt(struct in6pcb *);
int in6_pcbsetport(struct sockaddr_in6 *, struct in6pcb *, struct lwp *);
extern struct rtentry *
Index: src/sys/netinet6/in6_src.c
diff -u src/sys/netinet6/in6_src.c:1.56 src/sys/netinet6/in6_src.c:1.57
--- src/sys/netinet6/in6_src.c:1.56 Tue Jan 20 21:27:36 2015
+++ src/sys/netinet6/in6_src.c Mon Apr 27 02:59:44 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: in6_src.c,v 1.56 2015/01/20 21:27:36 roy Exp $ */
+/* $NetBSD: in6_src.c,v 1.57 2015/04/27 02:59:44 ozaki-r Exp $ */
/* $KAME: in6_src.c,v 1.159 2005/10/19 01:40:32 t-momose Exp $ */
/*
@@ -66,7 +66,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in6_src.c,v 1.56 2015/01/20 21:27:36 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6_src.c,v 1.57 2015/04/27 02:59:44 ozaki-r Exp $");
#include "opt_inet.h"
@@ -788,6 +788,21 @@ in6_selecthlim(struct in6pcb *in6p, stru
return (ip6_defhlim);
}
+int
+in6_selecthlim_rt(struct in6pcb *in6p)
+{
+ struct rtentry *rt;
+
+ if (in6p == NULL)
+ return in6_selecthlim(in6p, NULL);
+
+ rt = rtcache_validate(&in6p->in6p_route);
+ if (rt != NULL)
+ return in6_selecthlim(in6p, rt->rt_ifp);
+ else
+ return in6_selecthlim(in6p, NULL);
+}
+
/*
* Find an empty port and set it to the specified PCB.
*/
Index: src/sys/netinet6/udp6_output.c
diff -u src/sys/netinet6/udp6_output.c:1.47 src/sys/netinet6/udp6_output.c:1.48
--- src/sys/netinet6/udp6_output.c:1.47 Fri Dec 5 18:45:37 2014
+++ src/sys/netinet6/udp6_output.c Mon Apr 27 02:59:44 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: udp6_output.c,v 1.47 2014/12/05 18:45:37 seanb Exp $ */
+/* $NetBSD: udp6_output.c,v 1.48 2015/04/27 02:59:44 ozaki-r Exp $ */
/* $KAME: udp6_output.c,v 1.43 2001/10/15 09:19:52 itojun Exp $ */
/*
@@ -62,7 +62,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: udp6_output.c,v 1.47 2014/12/05 18:45:37 seanb Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udp6_output.c,v 1.48 2015/04/27 02:59:44 ozaki-r Exp $");
#include "opt_inet.h"
@@ -80,7 +80,6 @@ __KERNEL_RCSID(0, "$NetBSD: udp6_output.
#include <sys/domain.h>
#include <net/if.h>
-#include <net/route.h>
#include <net/if_types.h>
#include <netinet/in.h>
@@ -115,7 +114,6 @@ udp6_output(struct in6pcb * const in6p,
struct mbuf * const addr6, struct mbuf * const control,
struct lwp * const l)
{
- struct rtentry *rt;
u_int32_t ulen = m->m_pkthdr.len;
u_int32_t plen = sizeof(struct udphdr) + ulen;
struct ip6_hdr *ip6;
@@ -358,9 +356,7 @@ udp6_output(struct in6pcb * const in6p,
ip6->ip6_plen = htons((u_int16_t)plen);
#endif
ip6->ip6_nxt = IPPROTO_UDP;
- ip6->ip6_hlim = in6_selecthlim(in6p,
- (rt = rtcache_validate(&in6p->in6p_route)) != NULL
- ? rt->rt_ifp : NULL);
+ ip6->ip6_hlim = in6_selecthlim_rt(in6p);
ip6->ip6_src = *laddr;
ip6->ip6_dst = *faddr;