...at least better than OpenBSD's source code.
This diff gets rid of the horrible per-ifp autoconf'd-ndp only hoplimit.
Alexander verified that this is not mandatory in the corresponding RFCs
and what really matters is the per-PCB specified hop limit.
See how this simplifies a lot of rt_ifp usages?
Ok?
Index: netinet/in_pcb.h
===================================================================
RCS file: /cvs/src/sys/netinet/in_pcb.h,v
retrieving revision 1.90
diff -u -p -r1.90 in_pcb.h
--- netinet/in_pcb.h 22 Sep 2015 09:34:39 -0000 1.90
+++ netinet/in_pcb.h 24 Oct 2015 13:49:47 -0000
@@ -287,7 +287,7 @@ struct rtentry *
int in6_pcbnotify(struct inpcbtable *, struct sockaddr_in6 *,
u_int, const struct sockaddr_in6 *, u_int, u_int, int, void *,
void (*)(struct inpcb *, int));
-int in6_selecthlim(struct inpcb *, struct ifnet *);
+int in6_selecthlim(struct inpcb *);
int in6_pcbsetport(struct in6_addr *, struct inpcb *, struct proc *);
#endif /* _KERNEL */
#endif /* _NETINET_IN_PCB_H_ */
Index: netinet/tcp_input.c
===================================================================
RCS file: /cvs/src/sys/netinet/tcp_input.c,v
retrieving revision 1.305
diff -u -p -r1.305 tcp_input.c
--- netinet/tcp_input.c 11 Sep 2015 08:17:06 -0000 1.305
+++ netinet/tcp_input.c 24 Oct 2015 13:50:20 -0000
@@ -4363,8 +4363,7 @@ syn_cache_respond(struct syn_cache *sc,
break;
#ifdef INET6
case AF_INET6:
- ip6->ip6_hlim = in6_selecthlim(NULL,
- ro->ro_rt ? ro->ro_rt->rt_ifp : NULL);
+ ip6->ip6_hlim = in6_selecthlim(NULL);
error = ip6_output(m, NULL /*XXX*/, (struct route_in6 *)ro, 0,
NULL, NULL);
Index: netinet/tcp_output.c
===================================================================
RCS file: /cvs/src/sys/netinet/tcp_output.c,v
retrieving revision 1.114
diff -u -p -r1.114 tcp_output.c
--- netinet/tcp_output.c 11 Sep 2015 08:17:06 -0000 1.114
+++ netinet/tcp_output.c 24 Oct 2015 13:50:25 -0000
@@ -1108,7 +1108,7 @@ send:
sizeof(struct ip6_hdr);
packetlen = m->m_pkthdr.len;
ip6->ip6_nxt = IPPROTO_TCP;
- ip6->ip6_hlim = in6_selecthlim(tp->t_inpcb, NULL);
+ ip6->ip6_hlim = in6_selecthlim(tp->t_inpcb);
#ifdef TCP_ECN
if (needect)
ip6->ip6_flow |= htonl(IPTOS_ECN_ECT0 << 20);
Index: netinet/tcp_subr.c
===================================================================
RCS file: /cvs/src/sys/netinet/tcp_subr.c,v
retrieving revision 1.149
diff -u -p -r1.149 tcp_subr.c
--- netinet/tcp_subr.c 2 Oct 2015 09:51:54 -0000 1.149
+++ netinet/tcp_subr.c 24 Oct 2015 13:50:04 -0000
@@ -254,7 +254,7 @@ tcp_template(tp)
ip6->ip6_nxt = IPPROTO_TCP;
ip6->ip6_plen = htons(sizeof(struct tcphdr)); /*XXX*/
- ip6->ip6_hlim = in6_selecthlim(inp, NULL); /*XXX*/
+ ip6->ip6_hlim = in6_selecthlim(inp); /*XXX*/
th = (struct tcphdr *)(mtod(m, caddr_t) +
sizeof(struct ip6_hdr));
@@ -400,7 +400,7 @@ tcp_respond(struct tcpcb *tp, caddr_t te
case AF_INET6:
ip6->ip6_flow = htonl(0x60000000);
ip6->ip6_nxt = IPPROTO_TCP;
- ip6->ip6_hlim = in6_selecthlim(tp ? tp->t_inpcb : NULL, NULL);
/*XXX*/
+ ip6->ip6_hlim = in6_selecthlim(tp ? tp->t_inpcb : NULL);
/*XXX*/
ip6->ip6_plen = tlen - sizeof(struct ip6_hdr);
ip6->ip6_plen = htons(ip6->ip6_plen);
ip6_output(m, tp ? tp->t_inpcb->inp_outputopts6 : NULL,
Index: netinet6/in6_pcb.c
===================================================================
RCS file: /cvs/src/sys/netinet6/in6_pcb.c,v
retrieving revision 1.81
diff -u -p -r1.81 in6_pcb.c
--- netinet6/in6_pcb.c 20 Oct 2015 18:04:03 -0000 1.81
+++ netinet6/in6_pcb.c 24 Oct 2015 13:54:05 -0000
@@ -369,7 +369,6 @@ in6_pcbconnect(struct inpcb *inp, struct
{
struct in6_addr *in6a = NULL;
struct sockaddr_in6 *sin6 = mtod(nam, struct sockaddr_in6 *);
- struct ifnet *ifp = NULL; /* outgoing interface */
int error = 0;
struct sockaddr_in6 tmp;
@@ -412,10 +411,7 @@ in6_pcbconnect(struct inpcb *inp, struct
if (error)
return (error);
- if (rtisvalid(inp->inp_route6.ro_rt))
- ifp = inp->inp_route6.ro_rt->rt_ifp;
-
- inp->inp_ipv6.ip6_hlim = (u_int8_t)in6_selecthlim(inp, ifp);
+ inp->inp_ipv6.ip6_hlim = (u_int8_t)in6_selecthlim(inp);
if (in_pcblookup(inp->inp_table, &sin6->sin6_addr, sin6->sin6_port,
IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6) ? in6a : &inp->inp_laddr6,
Index: netinet6/in6_src.c
===================================================================
RCS file: /cvs/src/sys/netinet6/in6_src.c,v
retrieving revision 1.66
diff -u -p -r1.66 in6_src.c
--- netinet6/in6_src.c 24 Oct 2015 12:33:16 -0000 1.66
+++ netinet6/in6_src.c 24 Oct 2015 13:46:02 -0000
@@ -470,14 +470,12 @@ in6_selectif(struct sockaddr_in6 *dstsoc
* 3. The system default hoplimit.
*/
int
-in6_selecthlim(struct inpcb *in6p, struct ifnet *ifp)
+in6_selecthlim(struct inpcb *in6p)
{
if (in6p && in6p->inp_hops >= 0)
return (in6p->inp_hops);
- else if (ifp)
- return (ND_IFINFO(ifp)->chlim);
- else
- return (ip6_defhlim);
+
+ return (ip6_defhlim);
}
/*
Index: netinet6/nd6.c
===================================================================
RCS file: /cvs/src/sys/netinet6/nd6.c,v
retrieving revision 1.158
diff -u -p -r1.158 nd6.c
--- netinet6/nd6.c 22 Oct 2015 16:44:54 -0000 1.158
+++ netinet6/nd6.c 24 Oct 2015 13:46:09 -0000
@@ -147,7 +147,6 @@ nd6_ifattach(struct ifnet *ifp)
nd->initialized = 1;
- nd->chlim = IPV6_DEFHLIM;
nd->basereachable = REACHABLE_TIME;
nd->reachable = ND_COMPUTE_RTIME(nd->basereachable);
nd->retrans = RETRANS_TIMER;
Index: netinet6/nd6.h
===================================================================
RCS file: /cvs/src/sys/netinet6/nd6.h,v
retrieving revision 1.49
diff -u -p -r1.49 nd6.h
--- netinet6/nd6.h 31 Aug 2015 10:03:47 -0000 1.49
+++ netinet6/nd6.h 24 Oct 2015 13:46:11 -0000
@@ -56,7 +56,6 @@ struct nd_ifinfo {
u_int32_t retrans; /* Retrans Timer */
u_int32_t flags; /* Flags */
int recalctm; /* BaseReacable re-calculation timer */
- u_int8_t chlim; /* CurHopLimit */
u_int8_t initialized; /* Flag to see the entry is initialized */
/* the following 3 members are for privacy extension for addrconf */
u_int8_t randomseed0[8]; /* upper 64 bits of MD5 digest */
Index: netinet6/nd6_rtr.c
===================================================================
RCS file: /cvs/src/sys/netinet6/nd6_rtr.c,v
retrieving revision 1.126
diff -u -p -r1.126 nd6_rtr.c
--- netinet6/nd6_rtr.c 22 Oct 2015 15:37:47 -0000 1.126
+++ netinet6/nd6_rtr.c 24 Oct 2015 13:54:31 -0000
@@ -435,8 +435,12 @@ nd6_ra_input(struct mbuf *m, int off, in
}
if (nd_ra->nd_ra_retransmit)
ndi->retrans = ntohl(nd_ra->nd_ra_retransmit);
- if (nd_ra->nd_ra_curhoplimit)
- ndi->chlim = nd_ra->nd_ra_curhoplimit;
+ if (nd_ra->nd_ra_curhoplimit) {
+ /*
+ * Ignore it. The router doesn't know the size of the
+ * internet better than this source code.
+ */
+ }
dr = defrtrlist_update(&dr0);
}
Index: netinet6/raw_ip6.c
===================================================================
RCS file: /cvs/src/sys/netinet6/raw_ip6.c,v
retrieving revision 1.85
diff -u -p -r1.85 raw_ip6.c
--- netinet6/raw_ip6.c 19 Oct 2015 12:11:28 -0000 1.85
+++ netinet6/raw_ip6.c 24 Oct 2015 13:51:06 -0000
@@ -344,7 +344,6 @@ rip6_output(struct mbuf *m, ...)
u_int plen = m->m_pkthdr.len;
int error = 0;
struct ip6_pktopts opt, *optp = NULL, *origoptp;
- struct ifnet *oifp = NULL;
int type, code; /* for ICMPv6 output statistics only */
int priv = 0;
va_list ap;
@@ -421,8 +420,6 @@ rip6_output(struct mbuf *m, ...)
goto bad;
ip6->ip6_src = *in6a;
- if (rtisvalid(in6p->inp_route6.ro_rt))
- oifp = in6p->inp_route6.ro_rt->rt_ifp;
}
ip6->ip6_flow = in6p->inp_flowinfo & IPV6_FLOWINFO_MASK;
@@ -432,7 +429,7 @@ rip6_output(struct mbuf *m, ...)
ip6->ip6_plen = htons((u_short)plen);
#endif
ip6->ip6_nxt = in6p->inp_ipv6.ip6_nxt;
- ip6->ip6_hlim = in6_selecthlim(in6p, oifp);
+ ip6->ip6_hlim = in6_selecthlim(in6p);
if (so->so_proto->pr_protocol == IPPROTO_ICMPV6 ||
in6p->inp_cksum6 != -1) {
Index: netinet6/udp6_output.c
===================================================================
RCS file: /cvs/src/sys/netinet6/udp6_output.c,v
retrieving revision 1.38
diff -u -p -r1.38 udp6_output.c
--- netinet6/udp6_output.c 19 Oct 2015 12:11:28 -0000 1.38
+++ netinet6/udp6_output.c 24 Oct 2015 13:51:26 -0000
@@ -105,7 +105,6 @@ udp6_output(struct inpcb *in6p, struct m
struct ip6_pktopts *optp, opt;
struct sockaddr_in6 tmp;
struct proc *p = curproc; /* XXX */
- struct ifnet *ifp;
u_short fport;
if ((in6p->inp_socket->so_state & SS_PRIV) != 0)
@@ -207,10 +206,7 @@ udp6_output(struct inpcb *in6p, struct m
ip6->ip6_plen = htons((u_short)plen);
#endif
ip6->ip6_nxt = IPPROTO_UDP;
- ifp = NULL;
- if (rtisvalid(in6p->inp_route6.ro_rt))
- ifp = in6p->inp_route6.ro_rt->rt_ifp;
- ip6->ip6_hlim = in6_selecthlim(in6p, ifp);
+ ip6->ip6_hlim = in6_selecthlim(in6p);
ip6->ip6_src = *laddr;
ip6->ip6_dst = *faddr;