nat_cmd.c (47061) | nat_cmd.c (47695) |
---|---|
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 * $Id: alias_cmd.c,v 1.24 1999/05/08 11:05:59 brian Exp $ | 5 * $Id: alias_cmd.c,v 1.25 1999/05/12 09:48:39 brian Exp $ |
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> --- 294 unchanged lines hidden (view full) --- 308} 309 310static struct mbuf * 311alias_PadMbuf(struct mbuf *bp, int type) 312{ 313 struct mbuf **last; 314 int len; 315 | 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> --- 294 unchanged lines hidden (view full) --- 308} 309 310static struct mbuf * 311alias_PadMbuf(struct mbuf *bp, int type) 312{ 313 struct mbuf **last; 314 int len; 315 |
316 mbuf_SetType(bp, type); |
|
316 for (last = &bp, len = 0; *last != NULL; last = &(*last)->next) 317 len += (*last)->cnt; 318 319 len = MAX_MRU - len; 320 *last = mbuf_Alloc(len, type); 321 322 return bp; 323} 324 325static struct mbuf * 326alias_LayerPush(struct bundle *bundle, struct link *l, struct mbuf *bp, 327 int pri, u_short *proto) 328{ 329 if (!bundle->AliasEnabled || *proto != PROTO_IP) 330 return bp; 331 332 log_Printf(LogDEBUG, "alias_LayerPush: PROTO_IP -> PROTO_IP\n"); | 317 for (last = &bp, len = 0; *last != NULL; last = &(*last)->next) 318 len += (*last)->cnt; 319 320 len = MAX_MRU - len; 321 *last = mbuf_Alloc(len, type); 322 323 return bp; 324} 325 326static struct mbuf * 327alias_LayerPush(struct bundle *bundle, struct link *l, struct mbuf *bp, 328 int pri, u_short *proto) 329{ 330 if (!bundle->AliasEnabled || *proto != PROTO_IP) 331 return bp; 332 333 log_Printf(LogDEBUG, "alias_LayerPush: PROTO_IP -> PROTO_IP\n"); |
333 bp = mbuf_Contiguous(alias_PadMbuf(bp, MB_IPQ)); | 334 bp = mbuf_Contiguous(alias_PadMbuf(bp, MB_ALIASOUT)); |
334 PacketAliasOut(MBUF_CTOP(bp), bp->cnt); 335 bp->cnt = ntohs(((struct ip *)MBUF_CTOP(bp))->ip_len); 336 337 return bp; 338} 339 340static struct mbuf * 341alias_LayerPull(struct bundle *bundle, struct link *l, struct mbuf *bp, 342 u_short *proto) 343{ 344 struct ip *pip, *piip; 345 int ret; 346 struct mbuf **last; 347 char *fptr; 348 349 if (!bundle->AliasEnabled || *proto != PROTO_IP) 350 return bp; 351 352 log_Printf(LogDEBUG, "alias_LayerPull: PROTO_IP -> PROTO_IP\n"); | 335 PacketAliasOut(MBUF_CTOP(bp), bp->cnt); 336 bp->cnt = ntohs(((struct ip *)MBUF_CTOP(bp))->ip_len); 337 338 return bp; 339} 340 341static struct mbuf * 342alias_LayerPull(struct bundle *bundle, struct link *l, struct mbuf *bp, 343 u_short *proto) 344{ 345 struct ip *pip, *piip; 346 int ret; 347 struct mbuf **last; 348 char *fptr; 349 350 if (!bundle->AliasEnabled || *proto != PROTO_IP) 351 return bp; 352 353 log_Printf(LogDEBUG, "alias_LayerPull: PROTO_IP -> PROTO_IP\n"); |
353 bp = mbuf_Contiguous(alias_PadMbuf(bp, MB_IPIN)); | 354 bp = mbuf_Contiguous(alias_PadMbuf(bp, MB_ALIASIN)); |
354 pip = (struct ip *)MBUF_CTOP(bp); 355 piip = (struct ip *)((char *)pip + (pip->ip_hl << 2)); 356 357 if (pip->ip_p == IPPROTO_IGMP || 358 (pip->ip_p == IPPROTO_IPIP && IN_CLASSD(ntohl(piip->ip_dst.s_addr)))) 359 return bp; 360 361 ret = PacketAliasIn(MBUF_CTOP(bp), bp->cnt); --- 16 unchanged lines hidden (view full) --- 378 PacketAliasSaveFragment(fptr); 379 break; 380 381 case PKT_ALIAS_FOUND_HEADER_FRAGMENT: 382 /* Fetch all the saved fragments and chain them on the end of `bp' */ 383 last = &bp->pnext; 384 while ((fptr = PacketAliasGetFragment(MBUF_CTOP(bp))) != NULL) { 385 PacketAliasFragmentIn(MBUF_CTOP(bp), fptr); | 355 pip = (struct ip *)MBUF_CTOP(bp); 356 piip = (struct ip *)((char *)pip + (pip->ip_hl << 2)); 357 358 if (pip->ip_p == IPPROTO_IGMP || 359 (pip->ip_p == IPPROTO_IPIP && IN_CLASSD(ntohl(piip->ip_dst.s_addr)))) 360 return bp; 361 362 ret = PacketAliasIn(MBUF_CTOP(bp), bp->cnt); --- 16 unchanged lines hidden (view full) --- 379 PacketAliasSaveFragment(fptr); 380 break; 381 382 case PKT_ALIAS_FOUND_HEADER_FRAGMENT: 383 /* Fetch all the saved fragments and chain them on the end of `bp' */ 384 last = &bp->pnext; 385 while ((fptr = PacketAliasGetFragment(MBUF_CTOP(bp))) != NULL) { 386 PacketAliasFragmentIn(MBUF_CTOP(bp), fptr); |
386 *last = mbuf_Alloc(ntohs(((struct ip *)fptr)->ip_len), MB_IPIN); | 387 *last = mbuf_Alloc(ntohs(((struct ip *)fptr)->ip_len), MB_ALIASIN); |
387 memcpy(MBUF_CTOP(*last), fptr, (*last)->cnt); 388 free(fptr); 389 last = &(*last)->pnext; 390 } 391 break; 392 393 default: 394 mbuf_Free(bp); 395 bp = NULL; 396 break; 397 } 398 399 return bp; 400} 401 402struct layer aliaslayer = 403 { LAYER_ALIAS, "alias", alias_LayerPush, alias_LayerPull }; | 388 memcpy(MBUF_CTOP(*last), fptr, (*last)->cnt); 389 free(fptr); 390 last = &(*last)->pnext; 391 } 392 break; 393 394 default: 395 mbuf_Free(bp); 396 bp = NULL; 397 break; 398 } 399 400 return bp; 401} 402 403struct layer aliaslayer = 404 { LAYER_ALIAS, "alias", alias_LayerPush, alias_LayerPull }; |