| 114 | #define V_ipsendredirects VNET(ipsendredirects) |
| 115 | |
| 116 | static struct mbuf * |
| 117 | ip_redir_alloc(struct mbuf *m, struct nhop_object *nh, |
| 118 | struct ip *ip, in_addr_t *addr) |
| 119 | { |
| 120 | struct mbuf *mcopy = m_gethdr(M_NOWAIT, m->m_type); |
| 121 | |
| 122 | if (mcopy == NULL) |
| 123 | return (NULL); |
| 124 | |
| 125 | if (m_dup_pkthdr(mcopy, m, M_NOWAIT) == 0) { |
| 126 | /* |
| 127 | * It's probably ok if the pkthdr dup fails (because |
| 128 | * the deep copy of the tag chain failed), but for now |
| 129 | * be conservative and just discard the copy since |
| 130 | * code below may some day want the tags. |
| 131 | */ |
| 132 | m_free(mcopy); |
| 133 | return (NULL); |
| 134 | } |
| 135 | mcopy->m_len = min(ntohs(ip->ip_len), M_TRAILINGSPACE(mcopy)); |
| 136 | mcopy->m_pkthdr.len = mcopy->m_len; |
| 137 | m_copydata(m, 0, mcopy->m_len, mtod(mcopy, caddr_t)); |
| 138 | |
| 139 | if (nh != NULL && |
| 140 | ((nh->nh_flags & (NHF_REDIRECT|NHF_DEFAULT)) == 0)) { |
| 141 | struct in_ifaddr *nh_ia = (struct in_ifaddr *)(nh->nh_ifa); |
| 142 | u_long src = ntohl(ip->ip_src.s_addr); |
| 143 | |
| 144 | if (nh_ia != NULL && |
| 145 | (src & nh_ia->ia_subnetmask) == nh_ia->ia_subnet) { |
| 146 | if (nh->nh_flags & NHF_GATEWAY) |
| 147 | *addr = nh->gw4_sa.sin_addr.s_addr; |
| 148 | else |
| 149 | *addr = ip->ip_dst.s_addr; |
| 150 | } |
| 151 | } |
| 152 | return (mcopy); |
| 153 | } |
| 154 | |
| 155 | |
| 156 | static int |
no test coverage detected