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

Function m_pad

freebsd/netipsec/ipsec_mbuf.c:172–237  ·  view source on GitHub ↗

* m_pad(m, n) pads with bytes at the end. The packet header * length is updated, and a pointer to the first byte of the padding * (which is guaranteed to be all in one mbuf) is returned. */

Source from the content-addressed store, hash-verified

170 * (which is guaranteed to be all in one mbuf) is returned.
171 */
172caddr_t
173m_pad(struct mbuf *m, int n)
174{
175 struct mbuf *m0, *m1;
176 int len, pad;
177 caddr_t retval;
178
179 if (n <= 0) { /* No stupid arguments. */
180 DPRINTF(("%s: pad length invalid (%d)\n", __func__, n));
181 m_freem(m);
182 return NULL;
183 }
184
185 len = m->m_pkthdr.len;
186 pad = n;
187 m0 = m;
188
189 while (m0->m_len < len) {
190 len -= m0->m_len;
191 m0 = m0->m_next;
192 }
193
194 if (m0->m_len != len) {
195 DPRINTF(("%s: length mismatch (should be %d instead of %d)\n",
196 __func__, m->m_pkthdr.len,
197 m->m_pkthdr.len + m0->m_len - len));
198
199 m_freem(m);
200 return NULL;
201 }
202
203 /* Check for zero-length trailing mbufs, and find the last one. */
204 for (m1 = m0; m1->m_next; m1 = m1->m_next) {
205 if (m1->m_next->m_len != 0) {
206 DPRINTF(("%s: length mismatch (should be %d instead "
207 "of %d)\n", __func__,
208 m->m_pkthdr.len,
209 m->m_pkthdr.len + m1->m_next->m_len));
210
211 m_freem(m);
212 return NULL;
213 }
214
215 m0 = m1->m_next;
216 }
217
218 if (pad > M_TRAILINGSPACE(m0)) {
219 /* Add an mbuf to the chain. */
220 MGET(m1, M_NOWAIT, MT_DATA);
221 if (m1 == NULL) {
222 m_freem(m0);
223 DPRINTF(("%s: unable to get extra mbuf\n", __func__));
224 return NULL;
225 }
226
227 m0->m_next = m1;
228 m0 = m1;
229 m0->m_len = 0;

Callers 1

esp_outputFunction · 0.85

Calls 1

m_freemFunction · 0.50

Tested by

no test coverage detected