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

TOMOYO Linux Cross Reference
Linux/net/ipv6/netfilter/ip6t_ah.c

Version: ~ [ linux-6.4-rc3 ] ~ [ linux-6.3.4 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.30 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.113 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.180 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.243 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.283 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.315 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ 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.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-only
  2 /* Kernel module to match AH parameters. */
  3 
  4 /* (C) 2001-2002 Andras Kis-Szabo <kisza@sch.bme.hu>
  5  */
  6 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  7 #include <linux/module.h>
  8 #include <linux/skbuff.h>
  9 #include <linux/ip.h>
 10 #include <linux/ipv6.h>
 11 #include <linux/types.h>
 12 #include <net/checksum.h>
 13 #include <net/ipv6.h>
 14 
 15 #include <linux/netfilter/x_tables.h>
 16 #include <linux/netfilter_ipv6/ip6_tables.h>
 17 #include <linux/netfilter_ipv6/ip6t_ah.h>
 18 
 19 MODULE_LICENSE("GPL");
 20 MODULE_DESCRIPTION("Xtables: IPv6 IPsec-AH match");
 21 MODULE_AUTHOR("Andras Kis-Szabo <kisza@sch.bme.hu>");
 22 
 23 /* Returns 1 if the spi is matched by the range, 0 otherwise */
 24 static inline bool
 25 spi_match(u_int32_t min, u_int32_t max, u_int32_t spi, bool invert)
 26 {
 27         bool r;
 28 
 29         pr_debug("spi_match:%c 0x%x <= 0x%x <= 0x%x\n",
 30                  invert ? '!' : ' ', min, spi, max);
 31         r = (spi >= min && spi <= max) ^ invert;
 32         pr_debug(" result %s\n", r ? "PASS" : "FAILED");
 33         return r;
 34 }
 35 
 36 static bool ah_mt6(const struct sk_buff *skb, struct xt_action_param *par)
 37 {
 38         struct ip_auth_hdr _ah;
 39         const struct ip_auth_hdr *ah;
 40         const struct ip6t_ah *ahinfo = par->matchinfo;
 41         unsigned int ptr = 0;
 42         unsigned int hdrlen = 0;
 43         int err;
 44 
 45         err = ipv6_find_hdr(skb, &ptr, NEXTHDR_AUTH, NULL, NULL);
 46         if (err < 0) {
 47                 if (err != -ENOENT)
 48                         par->hotdrop = true;
 49                 return false;
 50         }
 51 
 52         ah = skb_header_pointer(skb, ptr, sizeof(_ah), &_ah);
 53         if (ah == NULL) {
 54                 par->hotdrop = true;
 55                 return false;
 56         }
 57 
 58         hdrlen = ipv6_authlen(ah);
 59 
 60         pr_debug("IPv6 AH LEN %u %u ", hdrlen, ah->hdrlen);
 61         pr_debug("RES %04X ", ah->reserved);
 62         pr_debug("SPI %u %08X\n", ntohl(ah->spi), ntohl(ah->spi));
 63 
 64         pr_debug("IPv6 AH spi %02X ",
 65                  spi_match(ahinfo->spis[0], ahinfo->spis[1],
 66                            ntohl(ah->spi),
 67                            !!(ahinfo->invflags & IP6T_AH_INV_SPI)));
 68         pr_debug("len %02X %04X %02X ",
 69                  ahinfo->hdrlen, hdrlen,
 70                  (!ahinfo->hdrlen ||
 71                   (ahinfo->hdrlen == hdrlen) ^
 72                   !!(ahinfo->invflags & IP6T_AH_INV_LEN)));
 73         pr_debug("res %02X %04X %02X\n",
 74                  ahinfo->hdrres, ah->reserved,
 75                  !(ahinfo->hdrres && ah->reserved));
 76 
 77         return spi_match(ahinfo->spis[0], ahinfo->spis[1],
 78                           ntohl(ah->spi),
 79                           !!(ahinfo->invflags & IP6T_AH_INV_SPI)) &&
 80                 (!ahinfo->hdrlen ||
 81                  (ahinfo->hdrlen == hdrlen) ^
 82                  !!(ahinfo->invflags & IP6T_AH_INV_LEN)) &&
 83                 !(ahinfo->hdrres && ah->reserved);
 84 }
 85 
 86 static int ah_mt6_check(const struct xt_mtchk_param *par)
 87 {
 88         const struct ip6t_ah *ahinfo = par->matchinfo;
 89 
 90         if (ahinfo->invflags & ~IP6T_AH_INV_MASK) {
 91                 pr_debug("unknown flags %X\n", ahinfo->invflags);
 92                 return -EINVAL;
 93         }
 94         return 0;
 95 }
 96 
 97 static struct xt_match ah_mt6_reg __read_mostly = {
 98         .name           = "ah",
 99         .family         = NFPROTO_IPV6,
100         .match          = ah_mt6,
101         .matchsize      = sizeof(struct ip6t_ah),
102         .checkentry     = ah_mt6_check,
103         .me             = THIS_MODULE,
104 };
105 
106 static int __init ah_mt6_init(void)
107 {
108         return xt_register_match(&ah_mt6_reg);
109 }
110 
111 static void __exit ah_mt6_exit(void)
112 {
113         xt_unregister_match(&ah_mt6_reg);
114 }
115 
116 module_init(ah_mt6_init);
117 module_exit(ah_mt6_exit);
118 

~ [ 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