sync with OpenBSD -current

This commit is contained in:
purplerain 2023-12-03 20:46:03 +00:00
parent 02d83d01a6
commit 005bcb25db
Signed by: purplerain
GPG key ID: F42C07F07E2E35B7
29 changed files with 312 additions and 230 deletions

View file

@ -1,4 +1,4 @@
/* $OpenBSD: icmp6.c,v 1.250 2023/11/28 13:23:20 bluhm Exp $ */
/* $OpenBSD: icmp6.c,v 1.251 2023/12/03 20:36:24 bluhm Exp $ */
/* $KAME: icmp6.c,v 1.217 2001/06/20 15:03:29 jinmei Exp $ */
/*
@ -1693,7 +1693,7 @@ icmp6_ctloutput(int op, struct socket *so, int level, int optname,
struct mbuf *m)
{
int error = 0;
struct inpcb *in6p = sotoinpcb(so);
struct inpcb *inp = sotoinpcb(so);
if (level != IPPROTO_ICMPV6)
return EINVAL;
@ -1710,11 +1710,11 @@ icmp6_ctloutput(int op, struct socket *so, int level, int optname,
break;
}
p = mtod(m, struct icmp6_filter *);
if (!p || !in6p->inp_icmp6filt) {
if (!p || !inp->inp_icmp6filt) {
error = EINVAL;
break;
}
bcopy(p, in6p->inp_icmp6filt,
bcopy(p, inp->inp_icmp6filt,
sizeof(struct icmp6_filter));
error = 0;
break;
@ -1732,13 +1732,13 @@ icmp6_ctloutput(int op, struct socket *so, int level, int optname,
{
struct icmp6_filter *p;
if (!in6p->inp_icmp6filt) {
if (!inp->inp_icmp6filt) {
error = EINVAL;
break;
}
m->m_len = sizeof(struct icmp6_filter);
p = mtod(m, struct icmp6_filter *);
bcopy(in6p->inp_icmp6filt, p,
bcopy(inp->inp_icmp6filt, p,
sizeof(struct icmp6_filter));
error = 0;
break;

View file

@ -1,4 +1,4 @@
/* $OpenBSD: in6_pcb.c,v 1.128 2023/12/01 15:30:47 bluhm Exp $ */
/* $OpenBSD: in6_pcb.c,v 1.130 2023/12/03 20:36:24 bluhm Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -252,7 +252,7 @@ in6_pcbconnect(struct inpcb *inp, struct mbuf *nam)
int error;
struct sockaddr_in6 tmp;
KASSERT(inp->inp_flags & INP_IPV6);
KASSERT(ISSET(inp->inp_flags, INP_IPV6));
if ((error = in6_nam2sin6(nam, &sin6)))
return (error);
@ -373,10 +373,10 @@ in6_setpeeraddr(struct inpcb *inp, struct mbuf *nam)
int
in6_sockaddr(struct socket *so, struct mbuf *nam)
{
struct inpcb *in6p;
struct inpcb *inp;
in6p = sotoinpcb(so);
in6_setsockaddr(in6p, nam);
inp = sotoinpcb(so);
in6_setsockaddr(inp, nam);
return (0);
}
@ -384,10 +384,10 @@ in6_sockaddr(struct socket *so, struct mbuf *nam)
int
in6_peeraddr(struct socket *so, struct mbuf *nam)
{
struct inpcb *in6p;
struct inpcb *inp;
in6p = sotoinpcb(so);
in6_setpeeraddr(in6p, nam);
inp = sotoinpcb(so);
in6_setpeeraddr(inp, nam);
return (0);
}
@ -461,7 +461,7 @@ in6_pcbnotify(struct inpcbtable *table, struct sockaddr_in6 *dst,
rw_enter_write(&table->inpt_notify);
mtx_enter(&table->inpt_mtx);
TAILQ_FOREACH(inp, &table->inpt_queue, inp_queue) {
if ((inp->inp_flags & INP_IPV6) == 0)
if (!ISSET(inp->inp_flags, INP_IPV6))
continue;
/*

View file

@ -1,4 +1,4 @@
/* $OpenBSD: in6_src.c,v 1.88 2023/12/01 14:08:04 bluhm Exp $ */
/* $OpenBSD: in6_src.c,v 1.89 2023/12/03 20:36:24 bluhm Exp $ */
/* $KAME: in6_src.c,v 1.36 2001/02/06 04:08:17 itojun Exp $ */
/*
@ -422,10 +422,10 @@ in6_selectif(struct sockaddr_in6 *dstsock, struct ip6_pktopts *opts,
}
int
in6_selecthlim(struct inpcb *in6p)
in6_selecthlim(struct inpcb *inp)
{
if (in6p && in6p->inp_hops >= 0)
return (in6p->inp_hops);
if (inp && inp->inp_hops >= 0)
return (inp->inp_hops);
return (ip6_defhlim);
}

View file

@ -1,4 +1,4 @@
/* $OpenBSD: ip6_input.c,v 1.256 2023/09/16 09:33:27 mpi Exp $ */
/* $OpenBSD: ip6_input.c,v 1.257 2023/12/03 20:36:24 bluhm Exp $ */
/* $KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $ */
/*
@ -1012,11 +1012,11 @@ ip6_unknown_opt(struct mbuf **mp, u_int8_t *optp, int off)
* you are using IP6_EXTHDR_CHECK() not m_pulldown())
*/
void
ip6_savecontrol(struct inpcb *in6p, struct mbuf *m, struct mbuf **mp)
ip6_savecontrol(struct inpcb *inp, struct mbuf *m, struct mbuf **mp)
{
struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *);
if (in6p->inp_socket->so_options & SO_TIMESTAMP) {
if (inp->inp_socket->so_options & SO_TIMESTAMP) {
struct timeval tv;
m_microtime(m, &tv);
@ -1027,7 +1027,7 @@ ip6_savecontrol(struct inpcb *in6p, struct mbuf *m, struct mbuf **mp)
}
/* RFC 2292 sec. 5 */
if ((in6p->inp_flags & IN6P_PKTINFO) != 0) {
if ((inp->inp_flags & IN6P_PKTINFO) != 0) {
struct in6_pktinfo pi6;
memcpy(&pi6.ipi6_addr, &ip6->ip6_dst, sizeof(struct in6_addr));
if (IN6_IS_SCOPE_EMBED(&pi6.ipi6_addr))
@ -1040,7 +1040,7 @@ ip6_savecontrol(struct inpcb *in6p, struct mbuf *m, struct mbuf **mp)
mp = &(*mp)->m_next;
}
if ((in6p->inp_flags & IN6P_HOPLIMIT) != 0) {
if ((inp->inp_flags & IN6P_HOPLIMIT) != 0) {
int hlim = ip6->ip6_hlim & 0xff;
*mp = sbcreatecontrol((caddr_t) &hlim, sizeof(int),
IPV6_HOPLIMIT, IPPROTO_IPV6);
@ -1048,7 +1048,7 @@ ip6_savecontrol(struct inpcb *in6p, struct mbuf *m, struct mbuf **mp)
mp = &(*mp)->m_next;
}
if ((in6p->inp_flags & IN6P_TCLASS) != 0) {
if ((inp->inp_flags & IN6P_TCLASS) != 0) {
u_int32_t flowinfo;
int tclass;
@ -1069,7 +1069,7 @@ ip6_savecontrol(struct inpcb *in6p, struct mbuf *m, struct mbuf **mp)
* returned to normal user.
* See also RFC 2292 section 6 (or RFC 3542 section 8).
*/
if ((in6p->inp_flags & IN6P_HOPOPTS) != 0) {
if ((inp->inp_flags & IN6P_HOPOPTS) != 0) {
/*
* Check if a hop-by-hop options header is contained in the
* received packet, and if so, store the options as ancillary
@ -1114,7 +1114,7 @@ ip6_savecontrol(struct inpcb *in6p, struct mbuf *m, struct mbuf **mp)
}
/* IPV6_DSTOPTS and IPV6_RTHDR socket options */
if ((in6p->inp_flags & (IN6P_RTHDR | IN6P_DSTOPTS)) != 0) {
if ((inp->inp_flags & (IN6P_RTHDR | IN6P_DSTOPTS)) != 0) {
struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *);
int nxt = ip6->ip6_nxt, off = sizeof(struct ip6_hdr);
@ -1162,7 +1162,7 @@ ip6_savecontrol(struct inpcb *in6p, struct mbuf *m, struct mbuf **mp)
switch (nxt) {
case IPPROTO_DSTOPTS:
if (!(in6p->inp_flags & IN6P_DSTOPTS))
if (!(inp->inp_flags & IN6P_DSTOPTS))
break;
*mp = sbcreatecontrol((caddr_t)ip6e, elen,
@ -1173,7 +1173,7 @@ ip6_savecontrol(struct inpcb *in6p, struct mbuf *m, struct mbuf **mp)
break;
case IPPROTO_ROUTING:
if (!(in6p->inp_flags & IN6P_RTHDR))
if (!(inp->inp_flags & IN6P_RTHDR))
break;
*mp = sbcreatecontrol((caddr_t)ip6e, elen,

View file

@ -1,4 +1,4 @@
/* $OpenBSD: ip6_var.h,v 1.108 2023/12/01 14:08:04 bluhm Exp $ */
/* $OpenBSD: ip6_var.h,v 1.109 2023/12/03 20:36:24 bluhm Exp $ */
/* $KAME: ip6_var.h,v 1.33 2000/06/11 14:59:20 jinmei Exp $ */
/*
@ -301,7 +301,6 @@ extern uint8_t ip6_soiikey[IP6_SOIIKEY_LEN];
extern const struct pr_usrreqs rip6_usrreqs;
struct in6pcb;
struct inpcb;
int icmp6_ctloutput(int, struct socket *, int, int, struct mbuf *);

View file

@ -1,4 +1,4 @@
/* $OpenBSD: raw_ip6.c,v 1.176 2023/12/01 14:08:04 bluhm Exp $ */
/* $OpenBSD: raw_ip6.c,v 1.177 2023/12/03 20:36:24 bluhm Exp $ */
/* $KAME: raw_ip6.c,v 1.69 2001/03/04 15:55:44 itojun Exp $ */
/*
@ -135,7 +135,7 @@ rip6_input(struct mbuf **mp, int *offp, int proto, int af)
{
struct mbuf *m = *mp;
struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *);
struct inpcb *in6p;
struct inpcb *inp;
SIMPLEQ_HEAD(, inpcb) inpcblist;
struct in6_addr *key;
struct sockaddr_in6 rip6src;
@ -182,29 +182,29 @@ rip6_input(struct mbuf **mp, int *offp, int proto, int af)
SIMPLEQ_INIT(&inpcblist);
rw_enter_write(&rawin6pcbtable.inpt_notify);
mtx_enter(&rawin6pcbtable.inpt_mtx);
TAILQ_FOREACH(in6p, &rawin6pcbtable.inpt_queue, inp_queue) {
if (in6p->inp_socket->so_rcv.sb_state & SS_CANTRCVMORE)
TAILQ_FOREACH(inp, &rawin6pcbtable.inpt_queue, inp_queue) {
if (inp->inp_socket->so_rcv.sb_state & SS_CANTRCVMORE)
continue;
if (rtable_l2(in6p->inp_rtableid) !=
if (rtable_l2(inp->inp_rtableid) !=
rtable_l2(m->m_pkthdr.ph_rtableid))
continue;
if (!(in6p->inp_flags & INP_IPV6))
if (!(inp->inp_flags & INP_IPV6))
continue;
if ((in6p->inp_ipv6.ip6_nxt || proto == IPPROTO_ICMPV6) &&
in6p->inp_ipv6.ip6_nxt != proto)
if ((inp->inp_ipv6.ip6_nxt || proto == IPPROTO_ICMPV6) &&
inp->inp_ipv6.ip6_nxt != proto)
continue;
if (!IN6_IS_ADDR_UNSPECIFIED(&in6p->inp_laddr6) &&
!IN6_ARE_ADDR_EQUAL(&in6p->inp_laddr6, key))
if (!IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6) &&
!IN6_ARE_ADDR_EQUAL(&inp->inp_laddr6, key))
continue;
if (!IN6_IS_ADDR_UNSPECIFIED(&in6p->inp_faddr6) &&
!IN6_ARE_ADDR_EQUAL(&in6p->inp_faddr6, &ip6->ip6_src))
if (!IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6) &&
!IN6_ARE_ADDR_EQUAL(&inp->inp_faddr6, &ip6->ip6_src))
continue;
if (proto == IPPROTO_ICMPV6 && in6p->inp_icmp6filt) {
if (ICMP6_FILTER_WILLBLOCK(type, in6p->inp_icmp6filt))
if (proto == IPPROTO_ICMPV6 && inp->inp_icmp6filt) {
if (ICMP6_FILTER_WILLBLOCK(type, inp->inp_icmp6filt))
continue;
}
if (proto != IPPROTO_ICMPV6 && in6p->inp_cksum6 != -1) {
if (proto != IPPROTO_ICMPV6 && inp->inp_cksum6 != -1) {
rip6stat_inc(rip6s_isum);
/*
* Although in6_cksum() does not need the position of
@ -214,7 +214,7 @@ rip6_input(struct mbuf **mp, int *offp, int proto, int af)
* invalid. Avoid overflow with user supplied offset.
*/
if (m->m_pkthdr.len < *offp + 2 ||
m->m_pkthdr.len - *offp - 2 < in6p->inp_cksum6 ||
m->m_pkthdr.len - *offp - 2 < inp->inp_cksum6 ||
in6_cksum(m, proto, *offp,
m->m_pkthdr.len - *offp)) {
rip6stat_inc(rip6s_badsum);
@ -222,8 +222,8 @@ rip6_input(struct mbuf **mp, int *offp, int proto, int af)
}
}
in_pcbref(in6p);
SIMPLEQ_INSERT_TAIL(&inpcblist, in6p, inp_notify);
in_pcbref(inp);
SIMPLEQ_INSERT_TAIL(&inpcblist, inp, inp_notify);
}
mtx_leave(&rawin6pcbtable.inpt_mtx);
@ -253,7 +253,7 @@ rip6_input(struct mbuf **mp, int *offp, int proto, int af)
return IPPROTO_DONE;
}
while ((in6p = SIMPLEQ_FIRST(&inpcblist)) != NULL) {
while ((inp = SIMPLEQ_FIRST(&inpcblist)) != NULL) {
struct mbuf *n, *opts = NULL;
SIMPLEQ_REMOVE_HEAD(&inpcblist, inp_notify);
@ -264,16 +264,16 @@ rip6_input(struct mbuf **mp, int *offp, int proto, int af)
if (n != NULL) {
int ret;
if (in6p->inp_flags & IN6P_CONTROLOPTS)
ip6_savecontrol(in6p, n, &opts);
if (inp->inp_flags & IN6P_CONTROLOPTS)
ip6_savecontrol(inp, n, &opts);
/* strip intermediate headers */
m_adj(n, *offp);
mtx_enter(&in6p->inp_mtx);
ret = sbappendaddr(in6p->inp_socket,
&in6p->inp_socket->so_rcv,
mtx_enter(&inp->inp_mtx);
ret = sbappendaddr(inp->inp_socket,
&inp->inp_socket->so_rcv,
sin6tosa(&rip6src), n, opts);
mtx_leave(&in6p->inp_mtx);
mtx_leave(&inp->inp_mtx);
if (ret == 0) {
/* should notify about lost packet */
@ -281,9 +281,9 @@ rip6_input(struct mbuf **mp, int *offp, int proto, int af)
m_freem(opts);
rip6stat_inc(rip6s_fullsock);
} else
sorwakeup(in6p->inp_socket);
sorwakeup(inp->inp_socket);
}
in_pcbunref(in6p);
in_pcbunref(inp);
}
rw_exit_write(&rawin6pcbtable.inpt_notify);
@ -332,7 +332,7 @@ rip6_ctlinput(int cmd, struct sockaddr *sa, u_int rdomain, void *d)
if (ip6 && cmd == PRC_MSGSIZE) {
int valid = 0;
struct inpcb *in6p;
struct inpcb *inp;
/*
* Check to see if we have a valid raw IPv6 socket
@ -341,11 +341,11 @@ rip6_ctlinput(int cmd, struct sockaddr *sa, u_int rdomain, void *d)
* XXX chase extension headers, or pass final nxt value
* from icmp6_notify_error()
*/
in6p = in6_pcblookup(&rawin6pcbtable, &sa6->sin6_addr, 0,
inp = in6_pcblookup(&rawin6pcbtable, &sa6->sin6_addr, 0,
&sa6_src->sin6_addr, 0, rdomain);
if (in6p && in6p->inp_ipv6.ip6_nxt &&
in6p->inp_ipv6.ip6_nxt == nxt)
if (inp && inp->inp_ipv6.ip6_nxt &&
inp->inp_ipv6.ip6_nxt == nxt)
valid = 1;
/*
@ -356,7 +356,7 @@ rip6_ctlinput(int cmd, struct sockaddr *sa, u_int rdomain, void *d)
* - ignore the MTU change notification.
*/
icmp6_mtudisc_update((struct ip6ctlparam *)d, valid);
in_pcbunref(in6p);
in_pcbunref(inp);
/*
* regardless of if we called icmp6_mtudisc_update(),
@ -381,7 +381,7 @@ rip6_output(struct mbuf *m, struct socket *so, struct sockaddr *dstaddr,
{
struct in6_addr *dst;
struct ip6_hdr *ip6;
struct inpcb *in6p;
struct inpcb *inp;
u_int plen = m->m_pkthdr.len;
int error = 0;
struct ip6_pktopts opt, *optp = NULL;
@ -389,19 +389,19 @@ rip6_output(struct mbuf *m, struct socket *so, struct sockaddr *dstaddr,
int priv = 0;
int flags;
in6p = sotoinpcb(so);
inp = sotoinpcb(so);
priv = 0;
if ((so->so_state & SS_PRIV) != 0)
priv = 1;
if (control) {
if ((error = ip6_setpktopts(control, &opt,
in6p->inp_outputopts6,
inp->inp_outputopts6,
priv, so->so_proto->pr_protocol)) != 0)
goto bad;
optp = &opt;
} else
optp = in6p->inp_outputopts6;
optp = inp->inp_outputopts6;
if (dstaddr->sa_family != AF_INET6) {
error = EAFNOSUPPORT;
@ -442,7 +442,7 @@ rip6_output(struct mbuf *m, struct socket *so, struct sockaddr *dstaddr,
/* KAME hack: embed scopeid */
if (in6_embedscope(&ip6->ip6_dst, satosin6(dstaddr),
optp, in6p->inp_moptions6) != 0) {
optp, inp->inp_moptions6) != 0) {
error = EINVAL;
goto bad;
}
@ -453,24 +453,24 @@ rip6_output(struct mbuf *m, struct socket *so, struct sockaddr *dstaddr,
{
const struct in6_addr *in6a;
error = in6_pcbselsrc(&in6a, satosin6(dstaddr), in6p, optp);
error = in6_pcbselsrc(&in6a, satosin6(dstaddr), inp, optp);
if (error)
goto bad;
ip6->ip6_src = *in6a;
}
ip6->ip6_flow = in6p->inp_flowinfo & IPV6_FLOWINFO_MASK;
ip6->ip6_flow = inp->inp_flowinfo & IPV6_FLOWINFO_MASK;
ip6->ip6_vfc &= ~IPV6_VERSION_MASK;
ip6->ip6_vfc |= IPV6_VERSION;
#if 0 /* ip6_plen will be filled in ip6_output. */
ip6->ip6_plen = htons((u_short)plen);
#endif
ip6->ip6_nxt = in6p->inp_ipv6.ip6_nxt;
ip6->ip6_hlim = in6_selecthlim(in6p);
ip6->ip6_nxt = inp->inp_ipv6.ip6_nxt;
ip6->ip6_hlim = in6_selecthlim(inp);
if (so->so_proto->pr_protocol == IPPROTO_ICMPV6 ||
in6p->inp_cksum6 != -1) {
inp->inp_cksum6 != -1) {
struct mbuf *n;
int off;
u_int16_t *sump;
@ -480,7 +480,7 @@ rip6_output(struct mbuf *m, struct socket *so, struct sockaddr *dstaddr,
if (so->so_proto->pr_protocol == IPPROTO_ICMPV6)
off = offsetof(struct icmp6_hdr, icmp6_cksum);
else
off = in6p->inp_cksum6;
off = inp->inp_cksum6;
if (plen < 2 || plen - 2 < off) {
error = EINVAL;
goto bad;
@ -499,20 +499,20 @@ rip6_output(struct mbuf *m, struct socket *so, struct sockaddr *dstaddr,
}
flags = 0;
if (in6p->inp_flags & IN6P_MINMTU)
if (inp->inp_flags & IN6P_MINMTU)
flags |= IPV6_MINMTU;
/* force routing table */
m->m_pkthdr.ph_rtableid = in6p->inp_rtableid;
m->m_pkthdr.ph_rtableid = inp->inp_rtableid;
#if NPF > 0
if (in6p->inp_socket->so_state & SS_ISCONNECTED &&
if (inp->inp_socket->so_state & SS_ISCONNECTED &&
so->so_proto->pr_protocol != IPPROTO_ICMPV6)
pf_mbuf_link_inpcb(m, in6p);
pf_mbuf_link_inpcb(m, inp);
#endif
error = ip6_output(m, optp, &in6p->inp_route6, flags,
in6p->inp_moptions6, in6p->inp_seclevel);
error = ip6_output(m, optp, &inp->inp_route6, flags,
inp->inp_moptions6, inp->inp_seclevel);
if (so->so_proto->pr_protocol == IPPROTO_ICMPV6) {
icmp6stat_inc(icp6s_outhist + type);
} else
@ -584,7 +584,7 @@ extern u_long rip6_recvspace;
int
rip6_attach(struct socket *so, int proto, int wait)
{
struct inpcb *in6p;
struct inpcb *inp;
int error;
if (so->so_pcb)
@ -600,37 +600,37 @@ rip6_attach(struct socket *so, int proto, int wait)
if ((error = in_pcballoc(so, &rawin6pcbtable, wait)))
return error;
in6p = sotoinpcb(so);
in6p->inp_ipv6.ip6_nxt = proto;
in6p->inp_cksum6 = -1;
inp = sotoinpcb(so);
inp->inp_ipv6.ip6_nxt = proto;
inp->inp_cksum6 = -1;
in6p->inp_icmp6filt = malloc(sizeof(struct icmp6_filter), M_PCB,
inp->inp_icmp6filt = malloc(sizeof(struct icmp6_filter), M_PCB,
wait == M_WAIT ? M_WAITOK : M_NOWAIT);
if (in6p->inp_icmp6filt == NULL) {
in_pcbdetach(in6p);
if (inp->inp_icmp6filt == NULL) {
in_pcbdetach(inp);
return ENOMEM;
}
ICMP6_FILTER_SETPASSALL(in6p->inp_icmp6filt);
ICMP6_FILTER_SETPASSALL(inp->inp_icmp6filt);
return 0;
}
int
rip6_detach(struct socket *so)
{
struct inpcb *in6p = sotoinpcb(so);
struct inpcb *inp = sotoinpcb(so);
soassertlocked(so);
if (in6p == NULL)
if (inp == NULL)
panic("%s", __func__);
#ifdef MROUTING
if (so == ip6_mrouter[in6p->inp_rtableid])
if (so == ip6_mrouter[inp->inp_rtableid])
ip6_mrouter_done(so);
#endif
free(in6p->inp_icmp6filt, M_PCB, sizeof(struct icmp6_filter));
in6p->inp_icmp6filt = NULL;
free(inp->inp_icmp6filt, M_PCB, sizeof(struct icmp6_filter));
inp->inp_icmp6filt = NULL;
in_pcbdetach(in6p);
in_pcbdetach(inp);
return (0);
}
@ -638,25 +638,25 @@ rip6_detach(struct socket *so)
void
rip6_lock(struct socket *so)
{
struct inpcb *in6p = sotoinpcb(so);
struct inpcb *inp = sotoinpcb(so);
NET_ASSERT_LOCKED();
mtx_enter(&in6p->inp_mtx);
mtx_enter(&inp->inp_mtx);
}
void
rip6_unlock(struct socket *so)
{
struct inpcb *in6p = sotoinpcb(so);
struct inpcb *inp = sotoinpcb(so);
NET_ASSERT_LOCKED();
mtx_leave(&in6p->inp_mtx);
mtx_leave(&inp->inp_mtx);
}
int
rip6_bind(struct socket *so, struct mbuf *nam, struct proc *p)
{
struct inpcb *in6p = sotoinpcb(so);
struct inpcb *inp = sotoinpcb(so);
struct sockaddr_in6 *addr;
int error;
@ -671,17 +671,17 @@ rip6_bind(struct socket *so, struct mbuf *nam, struct proc *p)
*/
addr->sin6_port = 0;
if ((error = in6_pcbaddrisavail(in6p, addr, 0, p)))
if ((error = in6_pcbaddrisavail(inp, addr, 0, p)))
return (error);
in6p->inp_laddr6 = addr->sin6_addr;
inp->inp_laddr6 = addr->sin6_addr;
return (0);
}
int
rip6_connect(struct socket *so, struct mbuf *nam)
{
struct inpcb *in6p = sotoinpcb(so);
struct inpcb *inp = sotoinpcb(so);
struct sockaddr_in6 *addr;
const struct in6_addr *in6a;
int error;
@ -692,12 +692,12 @@ rip6_connect(struct socket *so, struct mbuf *nam)
return (error);
/* Source address selection. XXX: need pcblookup? */
error = in6_pcbselsrc(&in6a, addr, in6p, in6p->inp_outputopts6);
error = in6_pcbselsrc(&in6a, addr, inp, inp->inp_outputopts6);
if (error)
return (error);
in6p->inp_laddr6 = *in6a;
in6p->inp_faddr6 = addr->sin6_addr;
inp->inp_laddr6 = *in6a;
inp->inp_faddr6 = addr->sin6_addr;
soisconnected(so);
return (0);
}
@ -705,14 +705,14 @@ rip6_connect(struct socket *so, struct mbuf *nam)
int
rip6_disconnect(struct socket *so)
{
struct inpcb *in6p = sotoinpcb(so);
struct inpcb *inp = sotoinpcb(so);
soassertlocked(so);
if ((so->so_state & SS_ISCONNECTED) == 0)
return (ENOTCONN);
in6p->inp_faddr6 = in6addr_any;
inp->inp_faddr6 = in6addr_any;
so->so_state &= ~SS_ISCONNECTED; /* XXX */
return (0);
}
@ -732,7 +732,7 @@ int
rip6_send(struct socket *so, struct mbuf *m, struct mbuf *nam,
struct mbuf *control)
{
struct inpcb *in6p = sotoinpcb(so);
struct inpcb *inp = sotoinpcb(so);
struct sockaddr_in6 dst;
int error;
@ -752,7 +752,7 @@ rip6_send(struct socket *so, struct mbuf *m, struct mbuf *nam,
error = EISCONN;
goto out;
}
dst.sin6_addr = in6p->inp_faddr6;
dst.sin6_addr = inp->inp_faddr6;
} else {
struct sockaddr_in6 *addr6;

View file

@ -1,4 +1,4 @@
/* $OpenBSD: udp6_output.c,v 1.62 2023/12/01 14:08:04 bluhm Exp $ */
/* $OpenBSD: udp6_output.c,v 1.63 2023/12/03 20:36:24 bluhm Exp $ */
/* $KAME: udp6_output.c,v 1.21 2001/02/07 11:51:54 itojun Exp $ */
/*
@ -93,7 +93,7 @@
* Per RFC 768, August, 1980.
*/
int
udp6_output(struct inpcb *in6p, struct mbuf *m, struct mbuf *addr6,
udp6_output(struct inpcb *inp, struct mbuf *m, struct mbuf *addr6,
struct mbuf *control)
{
u_int32_t ulen = m->m_pkthdr.len;
@ -107,15 +107,15 @@ udp6_output(struct inpcb *in6p, struct mbuf *m, struct mbuf *addr6,
struct proc *p = curproc; /* XXX */
u_short fport;
if ((in6p->inp_socket->so_state & SS_PRIV) != 0)
if ((inp->inp_socket->so_state & SS_PRIV) != 0)
priv = 1;
if (control) {
if ((error = ip6_setpktopts(control, &opt,
in6p->inp_outputopts6, priv, IPPROTO_UDP)) != 0)
inp->inp_outputopts6, priv, IPPROTO_UDP)) != 0)
goto release;
optp = &opt;
} else
optp = in6p->inp_outputopts6;
optp = inp->inp_outputopts6;
if (addr6) {
struct sockaddr_in6 *sin6;
@ -130,7 +130,7 @@ udp6_output(struct inpcb *in6p, struct mbuf *m, struct mbuf *addr6,
error = EADDRNOTAVAIL;
goto release;
}
if (!IN6_IS_ADDR_UNSPECIFIED(&in6p->inp_faddr6)) {
if (!IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6)) {
error = EISCONN;
goto release;
}
@ -144,40 +144,40 @@ udp6_output(struct inpcb *in6p, struct mbuf *m, struct mbuf *addr6,
/* KAME hack: embed scopeid */
if (in6_embedscope(&sin6->sin6_addr, sin6,
in6p->inp_outputopts6, in6p->inp_moptions6) != 0) {
inp->inp_outputopts6, inp->inp_moptions6) != 0) {
error = EINVAL;
goto release;
}
error = in6_pcbselsrc(&laddr, sin6, in6p, optp);
error = in6_pcbselsrc(&laddr, sin6, inp, optp);
if (error)
goto release;
if (in6p->inp_lport == 0){
error = in_pcbbind(in6p, NULL, p);
if (inp->inp_lport == 0){
error = in_pcbbind(inp, NULL, p);
if (error)
goto release;
}
if (!IN6_IS_ADDR_UNSPECIFIED(&in6p->inp_laddr6) &&
!IN6_ARE_ADDR_EQUAL(&in6p->inp_laddr6, laddr)) {
if (!IN6_IS_ADDR_UNSPECIFIED(&inp->inp_laddr6) &&
!IN6_ARE_ADDR_EQUAL(&inp->inp_laddr6, laddr)) {
valid.sin6_addr = *laddr;
valid.sin6_port = in6p->inp_lport;
valid.sin6_port = inp->inp_lport;
valid.sin6_scope_id = 0;
valid.sin6_family = AF_INET6;
valid.sin6_len = sizeof(valid);
error = in6_pcbaddrisavail(in6p, &valid, 0, p);
error = in6_pcbaddrisavail(inp, &valid, 0, p);
if (error)
goto release;
}
} else {
if (IN6_IS_ADDR_UNSPECIFIED(&in6p->inp_faddr6)) {
if (IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6)) {
error = ENOTCONN;
goto release;
}
laddr = &in6p->inp_laddr6;
faddr = &in6p->inp_faddr6;
fport = in6p->inp_fport;
laddr = &inp->inp_laddr6;
faddr = &inp->inp_faddr6;
fport = inp->inp_fport;
}
hlen = sizeof(struct ip6_hdr);
@ -196,7 +196,7 @@ udp6_output(struct inpcb *in6p, struct mbuf *m, struct mbuf *addr6,
* Stuff checksum and output datagram.
*/
udp6 = (struct udphdr *)(mtod(m, caddr_t) + hlen);
udp6->uh_sport = in6p->inp_lport; /* lport is always set in the PCB */
udp6->uh_sport = inp->inp_lport; /* lport is always set in the PCB */
udp6->uh_dport = fport;
if (plen <= 0xffff)
udp6->uh_ulen = htons((u_short)plen);
@ -205,35 +205,35 @@ udp6_output(struct inpcb *in6p, struct mbuf *m, struct mbuf *addr6,
udp6->uh_sum = 0;
ip6 = mtod(m, struct ip6_hdr *);
ip6->ip6_flow = in6p->inp_flowinfo & IPV6_FLOWINFO_MASK;
ip6->ip6_flow = inp->inp_flowinfo & IPV6_FLOWINFO_MASK;
ip6->ip6_vfc &= ~IPV6_VERSION_MASK;
ip6->ip6_vfc |= IPV6_VERSION;
#if 0 /* ip6_plen will be filled in ip6_output. */
ip6->ip6_plen = htons((u_short)plen);
#endif
ip6->ip6_nxt = IPPROTO_UDP;
ip6->ip6_hlim = in6_selecthlim(in6p);
ip6->ip6_hlim = in6_selecthlim(inp);
ip6->ip6_src = *laddr;
ip6->ip6_dst = *faddr;
m->m_pkthdr.csum_flags |= M_UDP_CSUM_OUT;
flags = 0;
if (in6p->inp_flags & IN6P_MINMTU)
if (inp->inp_flags & IN6P_MINMTU)
flags |= IPV6_MINMTU;
udpstat_inc(udps_opackets);
/* force routing table */
m->m_pkthdr.ph_rtableid = in6p->inp_rtableid;
m->m_pkthdr.ph_rtableid = inp->inp_rtableid;
#if NPF > 0
if (in6p->inp_socket->so_state & SS_ISCONNECTED)
pf_mbuf_link_inpcb(m, in6p);
if (inp->inp_socket->so_state & SS_ISCONNECTED)
pf_mbuf_link_inpcb(m, inp);
#endif
error = ip6_output(m, optp, &in6p->inp_route6,
flags, in6p->inp_moptions6, in6p->inp_seclevel);
error = ip6_output(m, optp, &inp->inp_route6,
flags, inp->inp_moptions6, inp->inp_seclevel);
goto releaseopt;
release: