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 #else
  48 #define MOD_INC_USE_COUNT
  49 #define MOD_DEC_USE_COUNT
  50 #endif 
  51 
  52 
  53 /*
  54  *      The IPIP protocol driver.
  55  *
  56  *      On entry here
  57  *              skb->data is the original IP header
  58  *              skb->ip_hdr points to the initial IP header.
  59  *              skb->h.raw points at the new header.
  60  */
  61 
  62 int ipip_rcv(struct sk_buff *skb, struct device *dev, struct options *opt, 
     /* [previous][next][first][last][top][bottom][index][help] */
  63                 __u32 daddr, unsigned short len, __u32 saddr,
  64                                    int redo, struct inet_protocol *protocol)
  65 {
  66 #ifdef CONFIG_IP_FIREWALL
  67         int err;
  68 #endif
  69         /* Don't unlink in the middle of a turnaround */
  70         MOD_INC_USE_COUNT;
  71 #ifdef TUNNEL_DEBUG
  72         printk("ipip_rcv: got a packet!\n");
  73 #endif
  74         /*
  75          *      Discard the original IP header
  76          */
  77          
  78         skb_pull(skb, ((struct iphdr *)skb->data)->ihl<<2);
  79         
  80         /*
  81          *      Adjust pointers
  82          */
  83          
  84         skb->h.iph=(struct iphdr *)skb->data;
  85         skb->ip_hdr=(struct iphdr *)skb->data;
  86         memset(skb->proto_priv, 0, sizeof(struct options));
  87         if (skb->ip_hdr->ihl > 5) {
  88           if (ip_options_compile(NULL, skb))
  89             return 0;
  90         }
  91         
  92 #ifdef CONFIG_IP_FIREWALL
  93         /*
  94          *      Check the firewall [well spotted Olaf]
  95          */
  96          
  97         if((err=ip_fw_chk(skb->ip_hdr,dev,ip_fw_blk_chain, ip_fw_blk_policy,0))<FW_ACCEPT)
  98         {
  99                 if(err==FW_REJECT)
 100                         icmp_send(skb,ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0 , dev);
 101                 kfree_skb(skb, FREE_READ);
 102                 return 0;
 103         }       
 104 #endif
 105 
 106         /*
 107          *      If you want to add LZ compressed IP or things like that here,
 108          *      and in drivers/net/tunnel.c are the places to add.
 109          */
 110         
 111         /* skb=lzw_uncompress(skb); */
 112         
 113         /*
 114          *      Feed to IP forward.
 115          */
 116          
 117         if(ip_forward(skb, dev, 0, daddr))
 118                 kfree_skb(skb, FREE_READ);
 119         MOD_DEC_USE_COUNT;
 120         return(0);
 121 }
 122 
 123 #ifdef MODULE
 124 static struct inet_protocol ipip_protocol = {
 125   ipip_rcv,             /* IPIP handler          */
 126   NULL,                 /* Will be UDP fraglist handler */
 127   NULL,                 /* TUNNEL error control    */
 128   0,                    /* next                 */
 129   IPPROTO_IPIP,         /* protocol ID          */
 130   0,                    /* copy                 */
 131   NULL,                 /* data                 */
 132   "IPIP"                /* name                 */
 133 };
 134 
 135 
 136 /*
 137  *      And now the modules code and kernel interface.
 138  */
 139 
 140 int init_module( void) 
     /* [previous][next][first][last][top][bottom][index][help] */
 141 {
 142         inet_add_protocol(&ipip_protocol);
 143         return 0;
 144 }
 145 
 146 void cleanup_module( void) 
     /* [previous][next][first][last][top][bottom][index][help] */
 147 {
 148         if ( inet_del_protocol(&ipip_protocol) < 0 )
 149                 printk("ipip close: can't remove protocol\n");
 150 }
 151 
 152 #endif
 153 #endif

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