-/* $OpenBSD: ip_divert.c,v 1.94 2024/02/11 18:14:26 mvs Exp $ */
+/* $OpenBSD: ip_divert.c,v 1.95 2024/03/05 09:45:13 bluhm Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
if ((error = in_nam2sin(nam, &sin)))
goto fail;
- /* Do basic sanity checks. */
- if (m->m_pkthdr.len < sizeof(struct ip))
+ if (m->m_pkthdr.len > IP_MAXPACKET) {
+ error = EMSGSIZE;
goto fail;
- if ((m = m_pullup(m, sizeof(struct ip))) == NULL) {
- /* m_pullup() has freed the mbuf, so just return. */
- divstat_inc(divs_errors);
- return (ENOBUFS);
}
- ip = mtod(m, struct ip *);
- if (ip->ip_v != IPVERSION)
+
+ m = rip_chkhdr(m, NULL);
+ if (m == NULL) {
+ error = EINVAL;
goto fail;
+ }
+
+ ip = mtod(m, struct ip *);
off = ip->ip_hl << 2;
- if (off < sizeof(struct ip) || ntohs(ip->ip_len) < off ||
- m->m_pkthdr.len < ntohs(ip->ip_len))
- goto fail;
dir = (sin->sin_addr.s_addr == INADDR_ANY ? PF_OUT : PF_IN);
min_hdrlen = 0;
break;
}
- if (min_hdrlen && m->m_pkthdr.len < off + min_hdrlen)
+ if (min_hdrlen && m->m_pkthdr.len < off + min_hdrlen) {
+ error = EINVAL;
goto fail;
+ }
m->m_pkthdr.pf.flags |= PF_TAG_DIVERTED_PACKET;
fail:
m_freem(m);
divstat_inc(divs_errors);
- return (error ? error : EINVAL);
+ return (error);
}
void
-/* $OpenBSD: ip_var.h,v 1.113 2024/02/13 12:22:09 bluhm Exp $ */
+/* $OpenBSD: ip_var.h,v 1.114 2024/03/05 09:45:13 bluhm Exp $ */
/* $NetBSD: ip_var.h,v 1.16 1996/02/13 23:43:20 christos Exp $ */
/*
int rip_input(struct mbuf **, int *, int, int);
int rip_output(struct mbuf *, struct socket *, struct sockaddr *,
struct mbuf *);
+struct mbuf *
+ rip_chkhdr(struct mbuf *, struct mbuf *);
int rip_attach(struct socket *, int, int);
int rip_detach(struct socket *);
void rip_lock(struct socket *);
-/* $OpenBSD: raw_ip.c,v 1.156 2024/02/11 18:14:26 mvs Exp $ */
+/* $OpenBSD: raw_ip.c,v 1.157 2024/03/05 09:45:13 bluhm Exp $ */
/* $NetBSD: raw_ip.c,v 1.25 1996/02/18 18:58:33 christos Exp $ */
/*
in_pcbinit(&rawcbtable, 1);
}
-struct mbuf *rip_chkhdr(struct mbuf *, struct mbuf *);
-
int
rip_input(struct mbuf **mp, int *offp, int proto, int af)
{