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

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

Version: ~ [ linux-5.16-rc3 ] ~ [ linux-5.15.5 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.82 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.162 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.218 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.256 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.291 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.293 ] ~ [ 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 // SPDX-License-Identifier: GPL-2.0-only
  2 /* Kernel module to match AH parameters. */
  3 /* (C) 1999-2000 Yon Uriarte <yon@astaro.de>
  4  */
  5 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  6 #include <linux/in.h>
  7 #include <linux/module.h>
  8 #include <linux/skbuff.h>
  9 #include <linux/ip.h>
 10 
 11 #include <linux/netfilter_ipv4/ipt_ah.h>
 12 #include <linux/netfilter/x_tables.h>
 13 
 14 MODULE_LICENSE("GPL");
 15 MODULE_AUTHOR("Yon Uriarte <yon@astaro.de>");
 16 MODULE_DESCRIPTION("Xtables: IPv4 IPsec-AH SPI match");
 17 
 18 /* Returns 1 if the spi is matched by the range, 0 otherwise */
 19 static inline bool
 20 spi_match(u_int32_t min, u_int32_t max, u_int32_t spi, bool invert)
 21 {
 22         bool r;
 23         pr_debug("spi_match:%c 0x%x <= 0x%x <= 0x%x\n",
 24                  invert ? '!' : ' ', min, spi, max);
 25         r = (spi >= min && spi <= max) ^ invert;
 26         pr_debug(" result %s\n", r ? "PASS" : "FAILED");
 27         return r;
 28 }
 29 
 30 static bool ah_mt(const struct sk_buff *skb, struct xt_action_param *par)
 31 {
 32         struct ip_auth_hdr _ahdr;
 33         const struct ip_auth_hdr *ah;
 34         const struct ipt_ah *ahinfo = par->matchinfo;
 35 
 36         /* Must not be a fragment. */
 37         if (par->fragoff != 0)
 38                 return false;
 39 
 40         ah = skb_header_pointer(skb, par->thoff, sizeof(_ahdr), &_ahdr);
 41         if (ah == NULL) {
 42                 /* We've been asked to examine this packet, and we
 43                  * can't.  Hence, no choice but to drop.
 44                  */
 45                 pr_debug("Dropping evil AH tinygram.\n");
 46                 par->hotdrop = true;
 47                 return false;
 48         }
 49 
 50         return spi_match(ahinfo->spis[0], ahinfo->spis[1],
 51                          ntohl(ah->spi),
 52                          !!(ahinfo->invflags & IPT_AH_INV_SPI));
 53 }
 54 
 55 static int ah_mt_check(const struct xt_mtchk_param *par)
 56 {
 57         const struct ipt_ah *ahinfo = par->matchinfo;
 58 
 59         /* Must specify no unknown invflags */
 60         if (ahinfo->invflags & ~IPT_AH_INV_MASK) {
 61                 pr_debug("unknown flags %X\n", ahinfo->invflags);
 62                 return -EINVAL;
 63         }
 64         return 0;
 65 }
 66 
 67 static struct xt_match ah_mt_reg __read_mostly = {
 68         .name           = "ah",
 69         .family         = NFPROTO_IPV4,
 70         .match          = ah_mt,
 71         .matchsize      = sizeof(struct ipt_ah),
 72         .proto          = IPPROTO_AH,
 73         .checkentry     = ah_mt_check,
 74         .me             = THIS_MODULE,
 75 };
 76 
 77 static int __init ah_mt_init(void)
 78 {
 79         return xt_register_match(&ah_mt_reg);
 80 }
 81 
 82 static void __exit ah_mt_exit(void)
 83 {
 84         xt_unregister_match(&ah_mt_reg);
 85 }
 86 
 87 module_init(ah_mt_init);
 88 module_exit(ah_mt_exit);
 89 

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