nat_cmd.c (51075) | nat_cmd.c (54912) |
---|---|
1/*- 2 * The code in this file was written by Eivind Eklund <perhaps@yes.no>, 3 * who places it in the public domain without restriction. 4 * | 1/*- 2 * The code in this file was written by Eivind Eklund <perhaps@yes.no>, 3 * who places it in the public domain without restriction. 4 * |
5 * $FreeBSD: head/usr.sbin/ppp/nat_cmd.c 51075 1999-09-08 07:34:52Z brian $ | 5 * $FreeBSD: head/usr.sbin/ppp/nat_cmd.c 54912 1999-12-20 20:29:47Z brian $ |
6 */ 7 8#include <sys/param.h> 9#include <netinet/in.h> 10#include <arpa/inet.h> 11#include <netdb.h> 12#include <netinet/in_systm.h> 13#include <netinet/in.h> --- 317 unchanged lines hidden (view full) --- 331 return 1; 332 } 333 334 PacketAliasPptp(addr); 335 return 0; 336} 337 338static struct mbuf * | 6 */ 7 8#include <sys/param.h> 9#include <netinet/in.h> 10#include <arpa/inet.h> 11#include <netdb.h> 12#include <netinet/in_systm.h> 13#include <netinet/in.h> --- 317 unchanged lines hidden (view full) --- 331 return 1; 332 } 333 334 PacketAliasPptp(addr); 335 return 0; 336} 337 338static struct mbuf * |
339nat_PadMbuf(struct mbuf *bp, int type) 340{ 341 struct mbuf **last; 342 int len; 343 344 mbuf_SetType(bp, type); 345 for (last = &bp, len = 0; *last != NULL; last = &(*last)->next) 346 len += (*last)->cnt; 347 348 len = MAX_MRU - len; 349 *last = mbuf_Alloc(len, type); 350 351 return bp; 352} 353 354static struct mbuf * | |
355nat_LayerPush(struct bundle *bundle, struct link *l, struct mbuf *bp, 356 int pri, u_short *proto) 357{ 358 if (!bundle->NatEnabled || *proto != PROTO_IP) 359 return bp; 360 361 log_Printf(LogDEBUG, "nat_LayerPush: PROTO_IP -> PROTO_IP\n"); | 339nat_LayerPush(struct bundle *bundle, struct link *l, struct mbuf *bp, 340 int pri, u_short *proto) 341{ 342 if (!bundle->NatEnabled || *proto != PROTO_IP) 343 return bp; 344 345 log_Printf(LogDEBUG, "nat_LayerPush: PROTO_IP -> PROTO_IP\n"); |
362 bp = mbuf_Contiguous(nat_PadMbuf(bp, MB_NATOUT)); 363 PacketAliasOut(MBUF_CTOP(bp), bp->cnt); 364 bp->cnt = ntohs(((struct ip *)MBUF_CTOP(bp))->ip_len); | 346 m_settype(bp, MB_NATOUT); 347 bp = m_pullup(bp); 348 PacketAliasOut(MBUF_CTOP(bp), bp->m_len); |
365 366 return bp; 367} 368 369static struct mbuf * 370nat_LayerPull(struct bundle *bundle, struct link *l, struct mbuf *bp, 371 u_short *proto) 372{ 373 struct ip *pip, *piip; 374 int ret, len; 375 struct mbuf **last; 376 char *fptr; 377 378 if (!bundle->NatEnabled || *proto != PROTO_IP) 379 return bp; 380 381 log_Printf(LogDEBUG, "nat_LayerPull: PROTO_IP -> PROTO_IP\n"); | 349 350 return bp; 351} 352 353static struct mbuf * 354nat_LayerPull(struct bundle *bundle, struct link *l, struct mbuf *bp, 355 u_short *proto) 356{ 357 struct ip *pip, *piip; 358 int ret, len; 359 struct mbuf **last; 360 char *fptr; 361 362 if (!bundle->NatEnabled || *proto != PROTO_IP) 363 return bp; 364 365 log_Printf(LogDEBUG, "nat_LayerPull: PROTO_IP -> PROTO_IP\n"); |
382 bp = mbuf_Contiguous(nat_PadMbuf(bp, MB_NATIN)); | 366 m_settype(bp, MB_NATIN); 367 bp = m_pullup(bp); |
383 pip = (struct ip *)MBUF_CTOP(bp); 384 piip = (struct ip *)((char *)pip + (pip->ip_hl << 2)); 385 386 if (pip->ip_p == IPPROTO_IGMP || 387 (pip->ip_p == IPPROTO_IPIP && IN_CLASSD(ntohl(piip->ip_dst.s_addr)))) 388 return bp; 389 | 368 pip = (struct ip *)MBUF_CTOP(bp); 369 piip = (struct ip *)((char *)pip + (pip->ip_hl << 2)); 370 371 if (pip->ip_p == IPPROTO_IGMP || 372 (pip->ip_p == IPPROTO_IPIP && IN_CLASSD(ntohl(piip->ip_dst.s_addr)))) 373 return bp; 374 |
390 ret = PacketAliasIn(MBUF_CTOP(bp), bp->cnt); | 375 ret = PacketAliasIn(MBUF_CTOP(bp), bp->m_len); |
391 | 376 |
392 bp->cnt = ntohs(pip->ip_len); 393 if (bp->cnt > MAX_MRU) { | 377 bp->m_len = ntohs(pip->ip_len); 378 if (bp->m_len > MAX_MRU) { |
394 log_Printf(LogWARN, "nat_LayerPull: Problem with IP header length (%d)\n", | 379 log_Printf(LogWARN, "nat_LayerPull: Problem with IP header length (%d)\n", |
395 bp->cnt); 396 mbuf_Free(bp); | 380 bp->m_len); 381 m_freem(bp); |
397 return NULL; 398 } 399 400 switch (ret) { 401 case PKT_ALIAS_OK: 402 break; 403 404 case PKT_ALIAS_UNRESOLVED_FRAGMENT: 405 /* Save the data for later */ | 382 return NULL; 383 } 384 385 switch (ret) { 386 case PKT_ALIAS_OK: 387 break; 388 389 case PKT_ALIAS_UNRESOLVED_FRAGMENT: 390 /* Save the data for later */ |
406 fptr = malloc(bp->cnt); 407 bp = mbuf_Read(bp, fptr, bp->cnt); | 391 fptr = malloc(bp->m_len); 392 bp = mbuf_Read(bp, fptr, bp->m_len); |
408 PacketAliasSaveFragment(fptr); 409 break; 410 411 case PKT_ALIAS_FOUND_HEADER_FRAGMENT: 412 /* Fetch all the saved fragments and chain them on the end of `bp' */ | 393 PacketAliasSaveFragment(fptr); 394 break; 395 396 case PKT_ALIAS_FOUND_HEADER_FRAGMENT: 397 /* Fetch all the saved fragments and chain them on the end of `bp' */ |
413 last = &bp->pnext; | 398 last = &bp->m_nextpkt; |
414 while ((fptr = PacketAliasGetFragment(MBUF_CTOP(bp))) != NULL) { 415 PacketAliasFragmentIn(MBUF_CTOP(bp), fptr); 416 len = ntohs(((struct ip *)fptr)->ip_len); | 399 while ((fptr = PacketAliasGetFragment(MBUF_CTOP(bp))) != NULL) { 400 PacketAliasFragmentIn(MBUF_CTOP(bp), fptr); 401 len = ntohs(((struct ip *)fptr)->ip_len); |
417 *last = mbuf_Alloc(len, MB_NATIN); | 402 *last = m_get(len, MB_NATIN); |
418 memcpy(MBUF_CTOP(*last), fptr, len); 419 free(fptr); | 403 memcpy(MBUF_CTOP(*last), fptr, len); 404 free(fptr); |
420 last = &(*last)->pnext; | 405 last = &(*last)->m_nextpkt; |
421 } 422 break; 423 424 default: | 406 } 407 break; 408 409 default: |
425 mbuf_Free(bp); | 410 m_freem(bp); |
426 bp = NULL; 427 break; 428 } 429 430 return bp; 431} 432 433struct layer natlayer = 434 { LAYER_NAT, "nat", nat_LayerPush, nat_LayerPull }; | 411 bp = NULL; 412 break; 413 } 414 415 return bp; 416} 417 418struct layer natlayer = 419 { LAYER_NAT, "nat", nat_LayerPush, nat_LayerPull }; |