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.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 |
316 mbuf_SetType(bp, type); |
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"); |
334 bp = mbuf_Contiguous(alias_PadMbuf(bp, MB_ALIASOUT)); |
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"); |
354 bp = mbuf_Contiguous(alias_PadMbuf(bp, MB_ALIASIN)); |
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); |
387 *last = mbuf_Alloc(ntohs(((struct ip *)fptr)->ip_len), MB_ALIASIN); |
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 }; |