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

TOMOYO Linux Cross Reference
Linux/net/netfilter/xt_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 
  3 /* (C) 1999-2000 Yon Uriarte <yon@astaro.de>
  4  *
  5  * This program is free software; you can redistribute it and/or modify
  6  * it under the terms of the GNU General Public License version 2 as
  7  * published by the Free Software Foundation.
  8  */
  9 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 10 #include <linux/module.h>
 11 #include <linux/skbuff.h>
 12 #include <linux/in.h>
 13 #include <linux/ip.h>
 14 
 15 #include <linux/netfilter/xt_esp.h>
 16 #include <linux/netfilter/x_tables.h>
 17 
 18 #include <linux/netfilter_ipv4/ip_tables.h>
 19 #include <linux/netfilter_ipv6/ip6_tables.h>
 20 
 21 MODULE_LICENSE("GPL");
 22 MODULE_AUTHOR("Yon Uriarte <yon@astaro.de>");
 23 MODULE_DESCRIPTION("Xtables: IPsec-ESP packet match");
 24 MODULE_ALIAS("ipt_esp");
 25 MODULE_ALIAS("ip6t_esp");
 26 
 27 /* Returns 1 if the spi is matched by the range, 0 otherwise */
 28 static inline bool
 29 spi_match(u_int32_t min, u_int32_t max, u_int32_t spi, bool invert)
 30 {
 31         bool r;
 32         pr_debug("spi_match:%c 0x%x <= 0x%x <= 0x%x\n",
 33                  invert ? '!' : ' ', min, spi, max);
 34         r = (spi >= min && spi <= max) ^ invert;
 35         pr_debug(" result %s\n", r ? "PASS" : "FAILED");
 36         return r;
 37 }
 38 
 39 static bool esp_mt(const struct sk_buff *skb, struct xt_action_param *par)
 40 {
 41         const struct ip_esp_hdr *eh;
 42         struct ip_esp_hdr _esp;
 43         const struct xt_esp *espinfo = par->matchinfo;
 44 
 45         /* Must not be a fragment. */
 46         if (par->fragoff != 0)
 47                 return false;
 48 
 49         eh = skb_header_pointer(skb, par->thoff, sizeof(_esp), &_esp);
 50         if (eh == NULL) {
 51                 /* We've been asked to examine this packet, and we
 52                  * can't.  Hence, no choice but to drop.
 53                  */
 54                 pr_debug("Dropping evil ESP tinygram.\n");
 55                 par->hotdrop = true;
 56                 return false;
 57         }
 58 
 59         return spi_match(espinfo->spis[0], espinfo->spis[1], ntohl(eh->spi),
 60                          !!(espinfo->invflags & XT_ESP_INV_SPI));
 61 }
 62 
 63 static int esp_mt_check(const struct xt_mtchk_param *par)
 64 {
 65         const struct xt_esp *espinfo = par->matchinfo;
 66 
 67         if (espinfo->invflags & ~XT_ESP_INV_MASK) {
 68                 pr_debug("unknown flags %X\n", espinfo->invflags);
 69                 return -EINVAL;
 70         }
 71 
 72         return 0;
 73 }
 74 
 75 static struct xt_match esp_mt_reg[] __read_mostly = {
 76         {
 77                 .name           = "esp",
 78                 .family         = NFPROTO_IPV4,
 79                 .checkentry     = esp_mt_check,
 80                 .match          = esp_mt,
 81                 .matchsize      = sizeof(struct xt_esp),
 82                 .proto          = IPPROTO_ESP,
 83                 .me             = THIS_MODULE,
 84         },
 85         {
 86                 .name           = "esp",
 87                 .family         = NFPROTO_IPV6,
 88                 .checkentry     = esp_mt_check,
 89                 .match          = esp_mt,
 90                 .matchsize      = sizeof(struct xt_esp),
 91                 .proto          = IPPROTO_ESP,
 92                 .me             = THIS_MODULE,
 93         },
 94 };
 95 
 96 static int __init esp_mt_init(void)
 97 {
 98         return xt_register_matches(esp_mt_reg, ARRAY_SIZE(esp_mt_reg));
 99 }
100 
101 static void __exit esp_mt_exit(void)
102 {
103         xt_unregister_matches(esp_mt_reg, ARRAY_SIZE(esp_mt_reg));
104 }
105 
106 module_init(esp_mt_init);
107 module_exit(esp_mt_exit);
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