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  *              Kai Schulte     :       Fixed #defines for IP_FIREWALL->FIREWALL
  14  *
  15  *      This program is free software; you can redistribute it and/or
  16  *      modify it under the terms of the GNU General Public License
  17  *      as published by the Free Software Foundation; either version
  18  *      2 of the License, or (at your option) any later version.
  19  *
  20  */
  21  
  22 #include <linux/types.h>
  23 #include <linux/sched.h>
  24 #include <linux/kernel.h>
  25 #include <linux/skbuff.h>
  26 #include <linux/netdevice.h>
  27 #include <linux/in.h>
  28 #include <net/datalink.h>
  29 #include <net/sock.h>
  30 #include <net/ip.h>
  31 #include <net/icmp.h>
  32 #include <linux/tcp.h>
  33 #include <linux/udp.h>
  34 #include <net/protocol.h>
  35 #include <net/ipip.h>
  36 #include <linux/firewall.h>
  37 
  38 #include <linux/config.h>
  39 
  40 #include <linux/module.h>
  41 
  42 #if ( defined(CONFIG_NET_IPIP) && defined(CONFIG_IP_FORWARD)) || defined(MODULE)
  43 
  44 
  45 /*
  46  *      The IPIP protocol driver.
  47  *
  48  *      On entry here
  49  *              skb->data is the original IP header
  50  *              skb->ip_hdr points to the initial IP header.
  51  *              skb->h.raw points at the new header.
  52  */
  53 
  54 int ipip_rcv(struct sk_buff *skb, struct device *dev, struct options *opt, 
     /* [previous][next][first][last][top][bottom][index][help] */
  55                 __u32 daddr, unsigned short len, __u32 saddr,
  56                                    int redo, struct inet_protocol *protocol)
  57 {
  58 #ifdef CONFIG_FIREWALL
  59         int err;
  60 #endif
  61         /* Don't unlink in the middle of a turnaround */
  62         MOD_INC_USE_COUNT;
  63 #ifdef TUNNEL_DEBUG
  64         printk("ipip_rcv: got a packet!\n");
  65 #endif
  66         /*
  67          *      Discard the original IP header
  68          */
  69          
  70         skb_pull(skb, ((struct iphdr *)skb->data)->ihl<<2);
  71         
  72         /*
  73          *      Adjust pointers
  74          */
  75          
  76         skb->h.iph=(struct iphdr *)skb->data;
  77         skb->ip_hdr=(struct iphdr *)skb->data;
  78         memset(skb->proto_priv, 0, sizeof(struct options));
  79         if (skb->ip_hdr->ihl > 5) 
  80         {
  81                 if (ip_options_compile(NULL, skb))
  82                         return 0;
  83         }
  84         
  85 #ifdef CONFIG_FIREWALL
  86         /*
  87          *      Check the firewall [well spotted Olaf]
  88          */
  89          
  90         if((err=call_in_firewall(PF_INET, skb, skb->ip_hdr))<FW_ACCEPT)
  91         {
  92                 if(err==FW_REJECT)
  93                         icmp_send(skb,ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0 , dev);
  94                 kfree_skb(skb, FREE_READ);
  95                 return 0;
  96         }       
  97 #endif
  98 
  99         /*
 100          *      If you want to add LZ compressed IP or things like that here,
 101          *      and in drivers/net/tunnel.c are the places to add.
 102          */
 103         
 104         /* skb=lzw_uncompress(skb); */
 105         
 106         /*
 107          *      Feed to IP forward.
 108          */
 109          
 110         if(ip_forward(skb, dev, 0, daddr))
 111                 kfree_skb(skb, FREE_READ);
 112         MOD_DEC_USE_COUNT;
 113         return(0);
 114 }
 115 
 116 #ifdef MODULE
 117 static struct inet_protocol ipip_protocol = {
 118   ipip_rcv,             /* IPIP handler          */
 119   NULL,                 /* Will be UDP fraglist handler */
 120   NULL,                 /* TUNNEL error control    */
 121   0,                    /* next                 */
 122   IPPROTO_IPIP,         /* protocol ID          */
 123   0,                    /* copy                 */
 124   NULL,                 /* data                 */
 125   "IPIP"                /* name                 */
 126 };
 127 
 128 
 129 /*
 130  *      And now the modules code and kernel interface.
 131  */
 132 
 133 int init_module( void) 
     /* [previous][next][first][last][top][bottom][index][help] */
 134 {
 135         inet_add_protocol(&ipip_protocol);
 136         return 0;
 137 }
 138 
 139 void cleanup_module( void) 
     /* [previous][next][first][last][top][bottom][index][help] */
 140 {
 141         if ( inet_del_protocol(&ipip_protocol) < 0 )
 142                 printk("ipip close: can't remove protocol\n");
 143 }
 144 
 145 #endif
 146 #endif

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