inpcb: gather v4/v6 handling code into in_pcballoc() from protocols

Reviewed by:		rrs, tuexen
Differential revision:	https://reviews.freebsd.org/D36062
This commit is contained in:
Gleb Smirnoff 2022-08-10 11:09:34 -07:00
parent d38a784b61
commit c7a62c925c
7 changed files with 14 additions and 22 deletions

View File

@ -635,12 +635,23 @@ in_pcballoc(struct socket *so, struct inpcbinfo *pcbinfo)
#endif /*IPSEC*/
#ifdef INET6
if (INP_SOCKAF(so) == AF_INET6) {
inp->inp_vflag |= INP_IPV6PROTO;
inp->inp_vflag |= INP_IPV6PROTO | INP_IPV6;
if (V_ip6_v6only)
inp->inp_flags |= IN6P_IPV6_V6ONLY;
#ifdef INET
else
inp->inp_vflag |= INP_IPV4;
#endif
if (V_ip6_auto_flowlabel)
inp->inp_flags |= IN6P_AUTOFLOWLABEL;
inp->in6p_hops = -1; /* use kernel default */
}
if (V_ip6_auto_flowlabel)
inp->inp_flags |= IN6P_AUTOFLOWLABEL;
#endif
#if defined(INET) && defined(INET6)
else
#endif
#ifdef INET
inp->inp_vflag |= INP_IPV4;
#endif
/*
* Routes in inpcb's can cache L2 as well; they are guaranteed

View File

@ -593,7 +593,6 @@ div_attach(struct socket *so, int proto, struct thread *td)
return error;
inp = (struct inpcb *)so->so_pcb;
inp->inp_ip_p = proto;
inp->inp_vflag |= INP_IPV4;
inp->inp_flags |= INP_HDRINCL;
INP_WUNLOCK(inp);
return 0;

View File

@ -857,7 +857,6 @@ rip_attach(struct socket *so, int proto, struct thread *td)
if (error)
return (error);
inp = (struct inpcb *)so->so_pcb;
inp->inp_vflag |= INP_IPV4;
inp->inp_ip_p = proto;
inp->inp_ip_ttl = V_ip_defttl;
INP_HASH_WLOCK(&V_ripcbinfo);

View File

@ -184,16 +184,6 @@ tcp_usr_attach(struct socket *so, int proto, struct thread *td)
if (error)
goto out;
inp = sotoinpcb(so);
#ifdef INET6
if (inp->inp_vflag & INP_IPV6PROTO) {
inp->inp_vflag |= INP_IPV6;
if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0)
inp->inp_vflag |= INP_IPV4;
inp->in6p_hops = -1; /* use kernel default */
}
else
#endif
inp->inp_vflag |= INP_IPV4;
tp = tcp_newtcpcb(inp);
if (tp == NULL) {
error = ENOBUFS;

View File

@ -1529,7 +1529,6 @@ udp_attach(struct socket *so, int proto, struct thread *td)
return (error);
inp = sotoinpcb(so);
inp->inp_vflag |= INP_IPV4;
inp->inp_ip_ttl = V_ip_defttl;
inp->inp_flowid = atomic_fetchadd_int(&udp_flowid, 1);
inp->inp_flowtype = M_HASHTYPE_OPAQUE;

View File

@ -658,9 +658,7 @@ rip6_attach(struct socket *so, int proto, struct thread *td)
return (error);
}
inp = (struct inpcb *)so->so_pcb;
inp->inp_vflag |= INP_IPV6;
inp->inp_ip_p = (long)proto;
inp->in6p_hops = -1; /* use kernel default */
inp->in6p_cksum = -1;
inp->in6p_icmp6filt = filter;
ICMP6_FILTER_SETPASSALL(inp->in6p_icmp6filt);

View File

@ -1045,10 +1045,6 @@ udp6_attach(struct socket *so, int proto, struct thread *td)
if (error)
return (error);
inp = (struct inpcb *)so->so_pcb;
inp->inp_vflag |= INP_IPV6;
if ((inp->inp_flags & IN6P_IPV6_V6ONLY) == 0)
inp->inp_vflag |= INP_IPV4;
inp->in6p_hops = -1; /* use kernel default */
inp->in6p_cksum = -1; /* just to be sure */
/*
* XXX: ugly!!