diff --git a/sys/netpfil/ipfw/ip_fw2.c b/sys/netpfil/ipfw/ip_fw2.c index 697ee145a943..17a19c27b1a4 100644 --- a/sys/netpfil/ipfw/ip_fw2.c +++ b/sys/netpfil/ipfw/ip_fw2.c @@ -993,18 +993,9 @@ send_reject6(struct ip_fw_args *args, int code, u_int hlen, struct ip6_hdr *ip6) * sends a reject message, consuming the mbuf passed as an argument. */ static void -send_reject(struct ip_fw_args *args, const ipfw_insn *cmd, int iplen, +send_reject(struct ip_fw_args *args, int code, int mtu, int iplen, struct ip *ip) { - int code, mtu; - - code = cmd->arg1; - if (code == ICMP_UNREACH_NEEDFRAG && - cmd->len == F_INSN_SIZE(ipfw_insn_u16)) - mtu = ((const ipfw_insn_u16 *)cmd)->ports[0]; - else - mtu = 0; - #if 0 /* XXX When ip is not guaranteed to be at mtod() we will * need to account for this */ @@ -1433,6 +1424,10 @@ ipfw_chk(struct ip_fw_args *args) int iplen = 0; int pktlen; + bool need_send_reject = false; + uint8_t reject_code; + uint16_t reject_mtu; + struct ipfw_dyn_info dyn_info; struct ip_fw *q = NULL; struct ip_fw_chain *chain = &V_layer3_chain; @@ -3077,8 +3072,14 @@ do { \ is_icmp_query(ICMP(ulp))) && !(m->m_flags & (M_BCAST|M_MCAST)) && !IN_MULTICAST(ntohl(dst_ip.s_addr))) { - send_reject(args, cmd, iplen, ip); - m = args->m; + reject_code = cmd->arg1; + if (reject_code == ICMP_UNREACH_NEEDFRAG && + cmd->len == F_INSN_SIZE(ipfw_insn_u16)) + reject_mtu = + ((ipfw_insn_u16 *)cmd)->ports[0]; + else + reject_mtu = 0; + need_send_reject = true; } /* FALLTHROUGH */ #ifdef INET6 @@ -3090,12 +3091,11 @@ do { \ !(m->m_flags & (M_BCAST|M_MCAST)) && !IN6_IS_ADDR_MULTICAST( &args->f_id.dst_ip6)) { - send_reject6(args, - cmd->opcode == O_REJECT ? - map_icmp_unreach(cmd->arg1): - cmd->arg1, hlen, - (struct ip6_hdr *)ip); - m = args->m; + reject_code = cmd->arg1; + if (cmd->opcode == O_REJECT) + reject_code = + map_icmp_unreach(reject_code); + need_send_reject = true; } /* FALLTHROUGH */ #endif @@ -3380,6 +3380,15 @@ do { \ printf("ipfw: ouch!, skip past end of rules, denying packet\n"); } IPFW_PF_RUNLOCK(chain); + if (need_send_reject) { +#ifdef INET6 + if (is_ipv6) + send_reject6(args, reject_code, hlen, + (struct ip6_hdr *)ip); + else +#endif + send_reject(args, reject_code, reject_mtu, iplen, ip); + } #ifdef __FreeBSD__ if (ucred_cache != NULL) crfree(ucred_cache);