root/net/ipv4/ipip.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. ipip_rcv
  2. init_module
  3. cleanup_module

   1 /*
   2  *      Linux NET3:     IP/IP protocol decoder. 
   3  *
   4  *      Authors:
   5  *              Sam Lantinga (slouken@cs.ucdavis.edu)  02/01/95
   6  *
   7  *      Fixes:
   8  *              Alan Cox        :       Merged and made usable non modular (its so tiny its silly as
   9  *                                      a module taking up 2 pages).
  10  *              Alan Cox        :       Fixed bug with 1.3.18 and IPIP not working (now needs to set skb->h.iph)
  11  *                                      to keep ip_forward happy.
  12  *              Alan Cox        :       More fixes for 1.3.21, and firewall fix. Maybe this will work soon 8).
  13  *
  14  *      This program is free software; you can redistribute it and/or
  15  *      modify it under the terms of the GNU General Public License
  16  *      as published by the Free Software Foundation; either version
  17  *      2 of the License, or (at your option) any later version.
  18  *
  19  */
  20  
  21 #include <linux/types.h>
  22 #include <linux/sched.h>
  23 #include <linux/kernel.h>
  24 #include <linux/skbuff.h>
  25 #include <linux/netdevice.h>
  26 #include <linux/in.h>
  27 #include <net/datalink.h>
  28 #include <net/sock.h>
  29 #include <net/ip.h>
  30 #include <net/icmp.h>
  31 #include <linux/tcp.h>
  32 #include <linux/udp.h>
  33 #include <net/protocol.h>
  34 #include <net/ipip.h>
  35 #include <linux/ip_fw.h>
  36 
  37 /*
  38  * NB. we must include the kernel idenfication string in to install the module.
  39  */
  40  
  41 #if ( defined(CONFIG_NET_IPIP) && defined(CONFIG_IP_FORWARD)) || defined(MODULE)
  42 #ifdef MODULE
  43 #include <linux/module.h>
  44 #include <linux/version.h>
  45 
  46 static char kernel_version[] = UTS_RELEASE;
  47 
  48 #else
  49 #define MOD_INC_USE_COUNT
  50 #define MOD_DEC_USE_COUNT
  51 #endif 
  52 
  53 
  54 /*
  55  *      The IPIP protocol driver.
  56  *
  57  *      On entry here
  58  *              skb->data is the original IP header
  59  *              skb->ip_hdr points to the initial IP header.
  60  *              skb->h.raw points at the new header.
  61  */
  62 
  63 int ipip_rcv(struct sk_buff *skb, struct device *dev, struct options *opt, 
     /* [previous][next][first][last][top][bottom][index][help] */
  64                 __u32 daddr, unsigned short len, __u32 saddr,
  65                                    int redo, struct inet_protocol *protocol)
  66 {
  67 #ifdef CONFIG_IP_FIREWALL
  68         int err;
  69 #endif
  70         /* Don't unlink in the middle of a turnaround */
  71         MOD_INC_USE_COUNT;
  72 #ifdef TUNNEL_DEBUG
  73         printk("ipip_rcv: got a packet!\n");
  74 #endif
  75         /*
  76          *      Discard the original IP header
  77          */
  78          
  79         skb_pull(skb, ((struct iphdr *)skb->data)->ihl<<2);
  80         
  81         /*
  82          *      Adjust pointers
  83          */
  84          
  85         skb->h.iph=(struct iphdr *)skb->data;
  86         skb->ip_hdr=(struct iphdr *)skb->data;
  87         
  88 #ifdef CONFIG_IP_FIREWALL
  89         /*
  90          *      Check the firewall [well spotted Olaf]
  91          */
  92          
  93         if((err=ip_fw_chk(skb->ip_hdr,dev,ip_fw_blk_chain, ip_fw_blk_policy,0))<FW_ACCEPT)
  94         {
  95                 if(err==FW_REJECT)
  96                         icmp_send(skb,ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0 , dev);
  97                 kfree_skb(skb, FREE_READ);
  98                 return 0;
  99         }       
 100 #endif
 101 
 102         /*
 103          *      If you want to add LZ compressed IP or things like that here,
 104          *      and in drivers/net/tunnel.c are the places to add.
 105          */
 106         
 107         /* skb=lzw_uncompress(skb); */
 108         
 109         /*
 110          *      Feed to IP forward.
 111          */
 112          
 113         if(ip_forward(skb, dev, 0, daddr, 0))
 114                 kfree_skb(skb, FREE_READ);
 115         MOD_DEC_USE_COUNT;
 116         return(0);
 117 }
 118 
 119 #ifdef MODULE
 120 static struct inet_protocol ipip_protocol = {
 121   ipip_rcv,             /* IPIP handler          */
 122   NULL,                 /* Will be UDP fraglist handler */
 123   NULL,                 /* TUNNEL error control    */
 124   0,                    /* next                 */
 125   IPPROTO_IPIP,         /* protocol ID          */
 126   0,                    /* copy                 */
 127   NULL,                 /* data                 */
 128   "IPIP"                /* name                 */
 129 };
 130 
 131 
 132 /*
 133  *      And now the modules code and kernel interface.
 134  */
 135 
 136 int init_module( void) 
     /* [previous][next][first][last][top][bottom][index][help] */
 137 {
 138         inet_add_protocol(&ipip_protocol);
 139         return 0;
 140 }
 141 
 142 void cleanup_module( void) 
     /* [previous][next][first][last][top][bottom][index][help] */
 143 {
 144         if ( inet_del_protocol(&ipip_protocol) < 0 )
 145                 printk("ipip close: can't remove protocol\n");
 146 }
 147 
 148 #endif
 149 #endif

/* [previous][next][first][last][top][bottom][index][help] */