~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/ipv4/netfilter/ipt_esp.c

Version: ~ [ linux-5.13-rc5 ] ~ [ linux-5.12.9 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.42 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.124 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.193 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.235 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.271 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.271 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* Kernel module to match ESP parameters. */
  2 #include <linux/module.h>
  3 #include <linux/skbuff.h>
  4 #include <linux/ip.h>
  5 
  6 #include <linux/netfilter_ipv4/ipt_esp.h>
  7 #include <linux/netfilter_ipv4/ip_tables.h>
  8 
  9 MODULE_LICENSE("GPL");
 10 MODULE_AUTHOR("Yon Uriarte <yon@astaro.de>");
 11 MODULE_DESCRIPTION("iptables ESP SPI match module");
 12 
 13 #ifdef DEBUG_CONNTRACK
 14 #define duprintf(format, args...) printk(format , ## args)
 15 #else
 16 #define duprintf(format, args...)
 17 #endif
 18 
 19 /* Returns 1 if the spi is matched by the range, 0 otherwise */
 20 static inline int
 21 spi_match(u_int32_t min, u_int32_t max, u_int32_t spi, int invert)
 22 {
 23         int r=0;
 24         duprintf("esp spi_match:%c 0x%x <= 0x%x <= 0x%x",invert? '!':' ',
 25                 min,spi,max);
 26         r=(spi >= min && spi <= max) ^ invert;
 27         duprintf(" result %s\n",r? "PASS" : "FAILED");
 28         return r;
 29 }
 30 
 31 static int
 32 match(const struct sk_buff *skb,
 33       const struct net_device *in,
 34       const struct net_device *out,
 35       const void *matchinfo,
 36       int offset,
 37       int *hotdrop)
 38 {
 39         struct ip_esp_hdr esp;
 40         const struct ipt_esp *espinfo = matchinfo;
 41 
 42         /* Must not be a fragment. */
 43         if (offset)
 44                 return 0;
 45 
 46         if (skb_copy_bits(skb, skb->nh.iph->ihl*4, &esp, sizeof(esp)) < 0) {
 47                 /* We've been asked to examine this packet, and we
 48                    can't.  Hence, no choice but to drop. */
 49                 duprintf("Dropping evil ESP tinygram.\n");
 50                 *hotdrop = 1;
 51                 return 0;
 52         }
 53 
 54         return spi_match(espinfo->spis[0], espinfo->spis[1],
 55                          ntohl(esp.spi),
 56                          !!(espinfo->invflags & IPT_ESP_INV_SPI));
 57 }
 58 
 59 /* Called when user tries to insert an entry of this type. */
 60 static int
 61 checkentry(const char *tablename,
 62            const struct ipt_ip *ip,
 63            void *matchinfo,
 64            unsigned int matchinfosize,
 65            unsigned int hook_mask)
 66 {
 67         const struct ipt_esp *espinfo = matchinfo;
 68 
 69         /* Must specify proto == ESP, and no unknown invflags */
 70         if (ip->proto != IPPROTO_ESP || (ip->invflags & IPT_INV_PROTO)) {
 71                 duprintf("ipt_esp: Protocol %u != %u\n", ip->proto,
 72                          IPPROTO_ESP);
 73                 return 0;
 74         }
 75         if (matchinfosize != IPT_ALIGN(sizeof(struct ipt_esp))) {
 76                 duprintf("ipt_esp: matchsize %u != %u\n",
 77                          matchinfosize, IPT_ALIGN(sizeof(struct ipt_esp)));
 78                 return 0;
 79         }
 80         if (espinfo->invflags & ~IPT_ESP_INV_MASK) {
 81                 duprintf("ipt_esp: unknown flags %X\n",
 82                          espinfo->invflags);
 83                 return 0;
 84         }
 85 
 86         return 1;
 87 }
 88 
 89 static struct ipt_match esp_match = {
 90         .name           = "esp",
 91         .match          = &match,
 92         .checkentry     = &checkentry,
 93         .me             = THIS_MODULE,
 94 };
 95 
 96 static int __init init(void)
 97 {
 98         return ipt_register_match(&esp_match);
 99 }
100 
101 static void __exit cleanup(void)
102 {
103         ipt_unregister_match(&esp_match);
104 }
105 
106 module_init(init);
107 module_exit(cleanup);
108 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp