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

TOMOYO Linux Cross Reference
Linux/net/netfilter/xt_ipcomp.c

Version: ~ [ linux-5.15-rc1 ] ~ [ linux-5.14.5 ] ~ [ linux-5.13.18 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.66 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.147 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.206 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.246 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.282 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.283 ] ~ [ 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 ] ~

Diff markup

Differences between /net/netfilter/xt_ipcomp.c (Version linux-4.7.10) and /net/netfilter/xt_ipcomp.c (Version linux-5.8.18)


                                                   >>   1 // SPDX-License-Identifier: GPL-2.0-or-later
  1 /*  Kernel module to match IPComp parameters f      2 /*  Kernel module to match IPComp parameters for IPv4 and IPv6
  2  *                                                  3  *
  3  *  Copyright (C) 2013 WindRiver                    4  *  Copyright (C) 2013 WindRiver
  4  *                                                  5  *
  5  *  Author:                                         6  *  Author:
  6  *  Fan Du <fan.du@windriver.com>                   7  *  Fan Du <fan.du@windriver.com>
  7  *                                                  8  *
  8  *  Based on:                                       9  *  Based on:
  9  *  net/netfilter/xt_esp.c                         10  *  net/netfilter/xt_esp.c
 10  *                                             << 
 11  *  This program is free software; you can red << 
 12  *  modify it under the terms of the GNU Gener << 
 13  *  as published by the Free Software Foundati << 
 14  *  2 of the License, or (at your option) any  << 
 15  */                                                11  */
 16                                                    12 
 17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt        13 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 18 #include <linux/in.h>                              14 #include <linux/in.h>
 19 #include <linux/module.h>                          15 #include <linux/module.h>
 20 #include <linux/skbuff.h>                          16 #include <linux/skbuff.h>
 21 #include <linux/ip.h>                              17 #include <linux/ip.h>
 22                                                    18 
 23 #include <linux/netfilter/xt_ipcomp.h>             19 #include <linux/netfilter/xt_ipcomp.h>
 24 #include <linux/netfilter/x_tables.h>              20 #include <linux/netfilter/x_tables.h>
 25                                                    21 
 26 MODULE_LICENSE("GPL");                             22 MODULE_LICENSE("GPL");
 27 MODULE_AUTHOR("Fan Du <fan.du@windriver.com>")     23 MODULE_AUTHOR("Fan Du <fan.du@windriver.com>");
 28 MODULE_DESCRIPTION("Xtables: IPv4/6 IPsec-IPCo     24 MODULE_DESCRIPTION("Xtables: IPv4/6 IPsec-IPComp SPI match");
                                                   >>  25 MODULE_ALIAS("ipt_ipcomp");
                                                   >>  26 MODULE_ALIAS("ip6t_ipcomp");
 29                                                    27 
 30 /* Returns 1 if the spi is matched by the rang     28 /* Returns 1 if the spi is matched by the range, 0 otherwise */
 31 static inline bool                                 29 static inline bool
 32 spi_match(u_int32_t min, u_int32_t max, u_int3     30 spi_match(u_int32_t min, u_int32_t max, u_int32_t spi, bool invert)
 33 {                                                  31 {
 34         bool r;                                    32         bool r;
 35         pr_debug("spi_match:%c 0x%x <= 0x%x <=     33         pr_debug("spi_match:%c 0x%x <= 0x%x <= 0x%x\n",
 36                  invert ? '!' : ' ', min, spi,     34                  invert ? '!' : ' ', min, spi, max);
 37         r = (spi >= min && spi <= max) ^ inver     35         r = (spi >= min && spi <= max) ^ invert;
 38         pr_debug(" result %s\n", r ? "PASS" :      36         pr_debug(" result %s\n", r ? "PASS" : "FAILED");
 39         return r;                                  37         return r;
 40 }                                                  38 }
 41                                                    39 
 42 static bool comp_mt(const struct sk_buff *skb,     40 static bool comp_mt(const struct sk_buff *skb, struct xt_action_param *par)
 43 {                                                  41 {
 44         struct ip_comp_hdr _comphdr;               42         struct ip_comp_hdr _comphdr;
 45         const struct ip_comp_hdr *chdr;            43         const struct ip_comp_hdr *chdr;
 46         const struct xt_ipcomp *compinfo = par     44         const struct xt_ipcomp *compinfo = par->matchinfo;
 47                                                    45 
 48         /* Must not be a fragment. */              46         /* Must not be a fragment. */
 49         if (par->fragoff != 0)                     47         if (par->fragoff != 0)
 50                 return false;                      48                 return false;
 51                                                    49 
 52         chdr = skb_header_pointer(skb, par->th     50         chdr = skb_header_pointer(skb, par->thoff, sizeof(_comphdr), &_comphdr);
 53         if (chdr == NULL) {                        51         if (chdr == NULL) {
 54                 /* We've been asked to examine     52                 /* We've been asked to examine this packet, and we
 55                  * can't.  Hence, no choice bu     53                  * can't.  Hence, no choice but to drop.
 56                  */                                54                  */
 57                 pr_debug("Dropping evil IPComp     55                 pr_debug("Dropping evil IPComp tinygram.\n");
 58                 par->hotdrop = true;               56                 par->hotdrop = true;
 59                 return 0;                      !!  57                 return false;
 60         }                                          58         }
 61                                                    59 
 62         return spi_match(compinfo->spis[0], co     60         return spi_match(compinfo->spis[0], compinfo->spis[1],
 63                          ntohs(chdr->cpi),         61                          ntohs(chdr->cpi),
 64                          !!(compinfo->invflags     62                          !!(compinfo->invflags & XT_IPCOMP_INV_SPI));
 65 }                                                  63 }
 66                                                    64 
 67 static int comp_mt_check(const struct xt_mtchk     65 static int comp_mt_check(const struct xt_mtchk_param *par)
 68 {                                                  66 {
 69         const struct xt_ipcomp *compinfo = par     67         const struct xt_ipcomp *compinfo = par->matchinfo;
 70                                                    68 
 71         /* Must specify no unknown invflags */     69         /* Must specify no unknown invflags */
 72         if (compinfo->invflags & ~XT_IPCOMP_IN     70         if (compinfo->invflags & ~XT_IPCOMP_INV_MASK) {
 73                 pr_err("unknown flags %X\n", c !!  71                 pr_info_ratelimited("unknown flags %X\n", compinfo->invflags);
 74                 return -EINVAL;                    72                 return -EINVAL;
 75         }                                          73         }
 76         return 0;                                  74         return 0;
 77 }                                                  75 }
 78                                                    76 
 79 static struct xt_match comp_mt_reg[] __read_mo     77 static struct xt_match comp_mt_reg[] __read_mostly = {
 80         {                                          78         {
 81                 .name           = "ipcomp",        79                 .name           = "ipcomp",
 82                 .family         = NFPROTO_IPV4     80                 .family         = NFPROTO_IPV4,
 83                 .match          = comp_mt,         81                 .match          = comp_mt,
 84                 .matchsize      = sizeof(struc     82                 .matchsize      = sizeof(struct xt_ipcomp),
 85                 .proto          = IPPROTO_COMP     83                 .proto          = IPPROTO_COMP,
 86                 .checkentry     = comp_mt_chec     84                 .checkentry     = comp_mt_check,
 87                 .me             = THIS_MODULE,     85                 .me             = THIS_MODULE,
 88         },                                         86         },
 89         {                                          87         {
 90                 .name           = "ipcomp",        88                 .name           = "ipcomp",
 91                 .family         = NFPROTO_IPV6     89                 .family         = NFPROTO_IPV6,
 92                 .match          = comp_mt,         90                 .match          = comp_mt,
 93                 .matchsize      = sizeof(struc     91                 .matchsize      = sizeof(struct xt_ipcomp),
 94                 .proto          = IPPROTO_COMP     92                 .proto          = IPPROTO_COMP,
 95                 .checkentry     = comp_mt_chec     93                 .checkentry     = comp_mt_check,
 96                 .me             = THIS_MODULE,     94                 .me             = THIS_MODULE,
 97         },                                         95         },
 98 };                                                 96 };
 99                                                    97 
100 static int __init comp_mt_init(void)               98 static int __init comp_mt_init(void)
101 {                                                  99 {
102         return xt_register_matches(comp_mt_reg    100         return xt_register_matches(comp_mt_reg, ARRAY_SIZE(comp_mt_reg));
103 }                                                 101 }
104                                                   102 
105 static void __exit comp_mt_exit(void)             103 static void __exit comp_mt_exit(void)
106 {                                                 104 {
107         xt_unregister_matches(comp_mt_reg, ARR    105         xt_unregister_matches(comp_mt_reg, ARRAY_SIZE(comp_mt_reg));
108 }                                                 106 }
109                                                   107 
110 module_init(comp_mt_init);                        108 module_init(comp_mt_init);
111 module_exit(comp_mt_exit);                        109 module_exit(comp_mt_exit);
112                                                   110 

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