MCPcopy Create free account
hub / github.com/F-Stack/f-stack / ip_redir_alloc

Function ip_redir_alloc

freebsd/netinet/ip_fastfwd.c:116–153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

114#define V_ipsendredirects VNET(ipsendredirects)
115
116static struct mbuf *
117ip_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
156static int

Callers 1

ip_fastfwd.cFile · 0.85

Calls 5

m_dup_pkthdrFunction · 0.85
minFunction · 0.85
m_copydataFunction · 0.85
m_gethdrFunction · 0.50
m_freeFunction · 0.50

Tested by

no test coverage detected