-/* $OpenBSD: ip_divert.c,v 1.89 2022/10/17 14:49:02 mvs Exp $ */
+/* $OpenBSD: ip_divert.c,v 1.90 2023/04/04 10:12:03 bluhm Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
struct inpcb *inp = NULL;
struct socket *so;
struct sockaddr_in sin;
+ struct ip *ip;
+ int off;
divstat_inc(divs_ipackets);
break;
}
if_put(ifp);
+ } else {
+ /*
+ * Calculate IP and protocol checksums for outbound packet
+ * diverted to userland. pf rule diverts before cksum offload.
+ */
+ ip = mtod(m, struct ip *);
+ off = ip->ip_hl << 2;
+
+ ip->ip_sum = 0;
+ ip->ip_sum = in_cksum(m, off);
+ in_proto_cksum_out(m, NULL);
}
mtx_enter(&inp->inp_mtx);
-/* $OpenBSD: ip6_divert.c,v 1.88 2022/10/17 14:49:02 mvs Exp $ */
+/* $OpenBSD: ip6_divert.c,v 1.89 2023/04/04 10:12:03 bluhm Exp $ */
/*
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
break;
}
if_put(ifp);
+ } else {
+ /*
+ * Calculate protocol checksum for outbound packet diverted
+ * to userland. pf out rule diverts before cksum offload.
+ */
+ in6_proto_cksum_out(m, NULL);
}
mtx_enter(&inp->inp_mtx);