Deleted Added
full compact
ip.c (31143) ip.c (31195)
1/*
2 * PPP IP Protocol Interface
3 *
4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
5 *
6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
7 *
8 * Redistribution and use in source and binary forms are permitted
9 * provided that the above copyright notice and this paragraph are
10 * duplicated in all such forms and that any documentation,
11 * advertising materials, and other materials related to such
12 * distribution and use acknowledge that the software was developed
13 * by the Internet Initiative Japan. The name of the
14 * IIJ may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 *
1/*
2 * PPP IP Protocol Interface
3 *
4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
5 *
6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
7 *
8 * Redistribution and use in source and binary forms are permitted
9 * provided that the above copyright notice and this paragraph are
10 * duplicated in all such forms and that any documentation,
11 * advertising materials, and other materials related to such
12 * distribution and use acknowledge that the software was developed
13 * by the Internet Initiative Japan. The name of the
14 * IIJ may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 *
20 * $Id: ip.c,v 1.28 1997/11/12 19:48:45 brian Exp $
20 * $Id: ip.c,v 1.29 1997/11/12 21:04:21 brian Exp $
21 *
22 * TODO:
23 * o Return ICMP message for filterd packet
24 * and optionaly record it into log.
25 */
26#include <sys/param.h>
21 *
22 * TODO:
23 * o Return ICMP message for filterd packet
24 * and optionaly record it into log.
25 */
26#include <sys/param.h>
27#include <sys/time.h>
28#include <sys/select.h>
29#include <sys/socket.h>
27#include <netinet/in.h>
28#include <netinet/in_systm.h>
29#include <netinet/ip.h>
30#include <netinet/ip_icmp.h>
31#include <netinet/udp.h>
32#include <netinet/tcp.h>
33#include <arpa/inet.h>
30#include <netinet/in.h>
31#include <netinet/in_systm.h>
32#include <netinet/ip.h>
33#include <netinet/ip_icmp.h>
34#include <netinet/udp.h>
35#include <netinet/tcp.h>
36#include <arpa/inet.h>
37#include <net/if.h>
38#include <net/if_var.h>
39#include <net/if_tun.h>
34
35#include <alias.h>
36#include <errno.h>
37#include <stdio.h>
38#include <stdlib.h>
39#include <string.h>
40#include <termios.h>
41#include <unistd.h>

--- 10 unchanged lines hidden (view full) ---

52#include "vars.h"
53#include "filter.h"
54#include "log.h"
55#include "os.h"
56#include "ipcp.h"
57#include "vjcomp.h"
58#include "lcp.h"
59#include "modem.h"
40
41#include <alias.h>
42#include <errno.h>
43#include <stdio.h>
44#include <stdlib.h>
45#include <string.h>
46#include <termios.h>
47#include <unistd.h>

--- 10 unchanged lines hidden (view full) ---

58#include "vars.h"
59#include "filter.h"
60#include "log.h"
61#include "os.h"
62#include "ipcp.h"
63#include "vjcomp.h"
64#include "lcp.h"
65#include "modem.h"
66#include "tun.h"
60#include "ip.h"
61
62static struct pppTimer IdleTimer;
63
64static void
65IdleTimeout()
66{
67 LogPrintf(LogPHASE, "Idle timer expired.\n");

--- 296 unchanged lines hidden (view full) ---

364}
365
366void
367IpInput(struct mbuf * bp)
368{ /* IN: Pointer to IP pakcet */
369 u_char *cp;
370 struct mbuf *wp;
371 int nb, nw;
67#include "ip.h"
68
69static struct pppTimer IdleTimer;
70
71static void
72IdleTimeout()
73{
74 LogPrintf(LogPHASE, "Idle timer expired.\n");

--- 296 unchanged lines hidden (view full) ---

371}
372
373void
374IpInput(struct mbuf * bp)
375{ /* IN: Pointer to IP pakcet */
376 u_char *cp;
377 struct mbuf *wp;
378 int nb, nw;
372 u_char tunbuff[MAX_MRU];
379 struct tun_data tun, *frag;
373
380
374 cp = tunbuff;
381 tun_fill_header(tun, AF_INET);
382 cp = tun.data;
375 nb = 0;
376 for (wp = bp; wp; wp = wp->next) { /* Copy to contiguous region */
377 memcpy(cp, MBUF_CTOP(wp), wp->cnt);
378 cp += wp->cnt;
379 nb += wp->cnt;
380 }
381
382 if (mode & MODE_ALIAS) {
383 int iresult;
384 char *fptr;
385
383 nb = 0;
384 for (wp = bp; wp; wp = wp->next) { /* Copy to contiguous region */
385 memcpy(cp, MBUF_CTOP(wp), wp->cnt);
386 cp += wp->cnt;
387 nb += wp->cnt;
388 }
389
390 if (mode & MODE_ALIAS) {
391 int iresult;
392 char *fptr;
393
386 iresult = VarPacketAliasIn(tunbuff, sizeof tunbuff);
387 nb = ntohs(((struct ip *) tunbuff)->ip_len);
394 iresult = VarPacketAliasIn(tun.data, sizeof tun.data);
395 nb = ntohs(((struct ip *) tun.data)->ip_len);
388
389 if (nb > MAX_MRU) {
390 LogPrintf(LogERROR, "IpInput: Problem with IP header length\n");
391 pfree(bp);
392 return;
393 }
394 if (iresult == PKT_ALIAS_OK
395 || iresult == PKT_ALIAS_FOUND_HEADER_FRAGMENT) {
396
397 if (nb > MAX_MRU) {
398 LogPrintf(LogERROR, "IpInput: Problem with IP header length\n");
399 pfree(bp);
400 return;
401 }
402 if (iresult == PKT_ALIAS_OK
403 || iresult == PKT_ALIAS_FOUND_HEADER_FRAGMENT) {
396 if (PacketCheck(tunbuff, nb, FL_IN) < 0) {
404 if (PacketCheck(tun.data, nb, FL_IN) < 0) {
397 pfree(bp);
398 return;
399 }
400 ipInOctets += nb;
401
405 pfree(bp);
406 return;
407 }
408 ipInOctets += nb;
409
402 nb = ntohs(((struct ip *) tunbuff)->ip_len);
403 nw = write(tun_out, tunbuff, nb);
410 nb = ntohs(((struct ip *) tun.data)->ip_len);
411 nb += sizeof(tun)-sizeof(tun.data);
412 nw = write(tun_out, &tun, nb);
404 if (nw != nb)
405 if (nw == -1)
406 LogPrintf(LogERROR, "IpInput: wrote %d, got %s\n", nb,
407 strerror(errno));
408 else
409 LogPrintf(LogERROR, "IpInput: wrote %d, got %d\n", nb, nw);
410
411 if (iresult == PKT_ALIAS_FOUND_HEADER_FRAGMENT) {
413 if (nw != nb)
414 if (nw == -1)
415 LogPrintf(LogERROR, "IpInput: wrote %d, got %s\n", nb,
416 strerror(errno));
417 else
418 LogPrintf(LogERROR, "IpInput: wrote %d, got %d\n", nb, nw);
419
420 if (iresult == PKT_ALIAS_FOUND_HEADER_FRAGMENT) {
412 while ((fptr = VarPacketAliasGetFragment(tunbuff)) != NULL) {
413 VarPacketAliasFragmentIn(tunbuff, fptr);
421 while ((fptr = VarPacketAliasGetFragment(tun.data)) != NULL) {
422 VarPacketAliasFragmentIn(tun.data, fptr);
414 nb = ntohs(((struct ip *) fptr)->ip_len);
423 nb = ntohs(((struct ip *) fptr)->ip_len);
415 nw = write(tun_out, fptr, nb);
424 frag = (struct tun_data *)((char *)fptr-sizeof(tun)+sizeof(tun.data));
425 nb += sizeof(tun)-sizeof(tun.data);
426 nw = write(tun_out, frag, nb);
416 if (nw != nb)
417 if (nw == -1)
418 LogPrintf(LogERROR, "IpInput: wrote %d, got %s\n", nb,
419 strerror(errno));
420 else
421 LogPrintf(LogERROR, "IpInput: wrote %d, got %d\n", nb, nw);
427 if (nw != nb)
428 if (nw == -1)
429 LogPrintf(LogERROR, "IpInput: wrote %d, got %s\n", nb,
430 strerror(errno));
431 else
432 LogPrintf(LogERROR, "IpInput: wrote %d, got %d\n", nb, nw);
422 free(fptr);
433 free(frag);
423 }
424 }
425 } else if (iresult == PKT_ALIAS_UNRESOLVED_FRAGMENT) {
434 }
435 }
436 } else if (iresult == PKT_ALIAS_UNRESOLVED_FRAGMENT) {
426 nb = ntohs(((struct ip *) tunbuff)->ip_len);
427 fptr = malloc(nb);
428 if (fptr == NULL)
437 nb = ntohs(((struct ip *) tun.data)->ip_len);
438 nb += sizeof(tun)-sizeof(tun.data);
439 frag = (struct tun_data *)malloc(nb);
440 if (frag == NULL)
429 LogPrintf(LogALERT, "IpInput: Cannot allocate memory for fragment\n");
430 else {
441 LogPrintf(LogALERT, "IpInput: Cannot allocate memory for fragment\n");
442 else {
431 memcpy(fptr, tunbuff, nb);
432 VarPacketAliasSaveFragment(fptr);
443 tun_fill_header(*frag, AF_INET);
444 memcpy(frag->data, tun.data, nb-sizeof(tun)+sizeof(tun.data));
445 VarPacketAliasSaveFragment(frag->data);
433 }
434 }
435 } else { /* no aliasing */
446 }
447 }
448 } else { /* no aliasing */
436 if (PacketCheck(tunbuff, nb, FL_IN) < 0) {
449 if (PacketCheck(tun.data, nb, FL_IN) < 0) {
437 pfree(bp);
438 return;
439 }
440 ipInOctets += nb;
450 pfree(bp);
451 return;
452 }
453 ipInOctets += nb;
441 nw = write(tun_out, tunbuff, nb);
454 nb += sizeof(tun)-sizeof(tun.data);
455 nw = write(tun_out, &tun, nb);
442 if (nw != nb)
443 if (nw == -1)
444 LogPrintf(LogERROR, "IpInput: wrote %d, got %s\n", nb, strerror(errno));
445 else
446 LogPrintf(LogERROR, "IpInput: wrote %d, got %d\n", nb, nw);
447 }
448 pfree(bp);
449

--- 54 unchanged lines hidden ---
456 if (nw != nb)
457 if (nw == -1)
458 LogPrintf(LogERROR, "IpInput: wrote %d, got %s\n", nb, strerror(errno));
459 else
460 LogPrintf(LogERROR, "IpInput: wrote %d, got %d\n", nb, nw);
461 }
462 pfree(bp);
463

--- 54 unchanged lines hidden ---