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

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

Version: ~ [ linux-5.4-rc3 ] ~ [ linux-5.3.6 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.79 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.149 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.196 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.196 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.75 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ 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 /* IP tables module for matching the value of the IPv4/IPv6 DSCP field
  2  *
  3  * (C) 2002 by Harald Welte <laforge@netfilter.org>
  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/ip.h>
 13 #include <linux/ipv6.h>
 14 #include <net/dsfield.h>
 15 
 16 #include <linux/netfilter/x_tables.h>
 17 #include <linux/netfilter/xt_dscp.h>
 18 
 19 MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
 20 MODULE_DESCRIPTION("Xtables: DSCP/TOS field match");
 21 MODULE_LICENSE("GPL");
 22 MODULE_ALIAS("ipt_dscp");
 23 MODULE_ALIAS("ip6t_dscp");
 24 MODULE_ALIAS("ipt_tos");
 25 MODULE_ALIAS("ip6t_tos");
 26 
 27 static bool
 28 dscp_mt(const struct sk_buff *skb, struct xt_action_param *par)
 29 {
 30         const struct xt_dscp_info *info = par->matchinfo;
 31         u_int8_t dscp = ipv4_get_dsfield(ip_hdr(skb)) >> XT_DSCP_SHIFT;
 32 
 33         return (dscp == info->dscp) ^ !!info->invert;
 34 }
 35 
 36 static bool
 37 dscp_mt6(const struct sk_buff *skb, struct xt_action_param *par)
 38 {
 39         const struct xt_dscp_info *info = par->matchinfo;
 40         u_int8_t dscp = ipv6_get_dsfield(ipv6_hdr(skb)) >> XT_DSCP_SHIFT;
 41 
 42         return (dscp == info->dscp) ^ !!info->invert;
 43 }
 44 
 45 static int dscp_mt_check(const struct xt_mtchk_param *par)
 46 {
 47         const struct xt_dscp_info *info = par->matchinfo;
 48 
 49         if (info->dscp > XT_DSCP_MAX) {
 50                 pr_info("dscp %x out of range\n", info->dscp);
 51                 return -EDOM;
 52         }
 53 
 54         return 0;
 55 }
 56 
 57 static bool tos_mt(const struct sk_buff *skb, struct xt_action_param *par)
 58 {
 59         const struct xt_tos_match_info *info = par->matchinfo;
 60 
 61         if (par->family == NFPROTO_IPV4)
 62                 return ((ip_hdr(skb)->tos & info->tos_mask) ==
 63                        info->tos_value) ^ !!info->invert;
 64         else
 65                 return ((ipv6_get_dsfield(ipv6_hdr(skb)) & info->tos_mask) ==
 66                        info->tos_value) ^ !!info->invert;
 67 }
 68 
 69 static struct xt_match dscp_mt_reg[] __read_mostly = {
 70         {
 71                 .name           = "dscp",
 72                 .family         = NFPROTO_IPV4,
 73                 .checkentry     = dscp_mt_check,
 74                 .match          = dscp_mt,
 75                 .matchsize      = sizeof(struct xt_dscp_info),
 76                 .me             = THIS_MODULE,
 77         },
 78         {
 79                 .name           = "dscp",
 80                 .family         = NFPROTO_IPV6,
 81                 .checkentry     = dscp_mt_check,
 82                 .match          = dscp_mt6,
 83                 .matchsize      = sizeof(struct xt_dscp_info),
 84                 .me             = THIS_MODULE,
 85         },
 86         {
 87                 .name           = "tos",
 88                 .revision       = 1,
 89                 .family         = NFPROTO_IPV4,
 90                 .match          = tos_mt,
 91                 .matchsize      = sizeof(struct xt_tos_match_info),
 92                 .me             = THIS_MODULE,
 93         },
 94         {
 95                 .name           = "tos",
 96                 .revision       = 1,
 97                 .family         = NFPROTO_IPV6,
 98                 .match          = tos_mt,
 99                 .matchsize      = sizeof(struct xt_tos_match_info),
100                 .me             = THIS_MODULE,
101         },
102 };
103 
104 static int __init dscp_mt_init(void)
105 {
106         return xt_register_matches(dscp_mt_reg, ARRAY_SIZE(dscp_mt_reg));
107 }
108 
109 static void __exit dscp_mt_exit(void)
110 {
111         xt_unregister_matches(dscp_mt_reg, ARRAY_SIZE(dscp_mt_reg));
112 }
113 
114 module_init(dscp_mt_init);
115 module_exit(dscp_mt_exit);
116 

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