Linux kernel & device driver programming

Cross-Referenced Linux and Device Driver Code

[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ]
Version: [ 2.6.11.8 ] [ 2.6.25 ] [ 2.6.25.8 ] [ 2.6.31.13 ] Architecture: [ i386 ]
  1 /* Kernel module to match FRAG parameters. */
  2 
  3 /* (C) 2001-2002 Andras Kis-Szabo <kisza@sch.bme.hu>
  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 
 10 #include <linux/module.h>
 11 #include <linux/skbuff.h>
 12 #include <linux/ipv6.h>
 13 #include <linux/types.h>
 14 #include <net/checksum.h>
 15 #include <net/ipv6.h>
 16 
 17 #include <linux/netfilter/x_tables.h>
 18 #include <linux/netfilter_ipv6/ip6_tables.h>
 19 #include <linux/netfilter_ipv6/ip6t_frag.h>
 20 
 21 MODULE_LICENSE("GPL");
 22 MODULE_DESCRIPTION("Xtables: IPv6 fragment match");
 23 MODULE_AUTHOR("Andras Kis-Szabo <kisza@sch.bme.hu>");
 24 
 25 /* Returns 1 if the id is matched by the range, 0 otherwise */
 26 static inline bool
 27 id_match(u_int32_t min, u_int32_t max, u_int32_t id, bool invert)
 28 {
 29         bool r;
 30         pr_debug("frag id_match:%c 0x%x <= 0x%x <= 0x%x", invert ? '!' : ' ',
 31                  min, id, max);
 32         r = (id >= min && id <= max) ^ invert;
 33         pr_debug(" result %s\n", r ? "PASS" : "FAILED");
 34         return r;
 35 }
 36 
 37 static bool
 38 frag_mt6(const struct sk_buff *skb, const struct net_device *in,
 39          const struct net_device *out, const struct xt_match *match,
 40          const void *matchinfo, int offset, unsigned int protoff,
 41          bool *hotdrop)
 42 {
 43         struct frag_hdr _frag;
 44         const struct frag_hdr *fh;
 45         const struct ip6t_frag *fraginfo = matchinfo;
 46         unsigned int ptr;
 47         int err;
 48 
 49         err = ipv6_find_hdr(skb, &ptr, NEXTHDR_FRAGMENT, NULL);
 50         if (err < 0) {
 51                 if (err != -ENOENT)
 52                         *hotdrop = true;
 53                 return false;
 54         }
 55 
 56         fh = skb_header_pointer(skb, ptr, sizeof(_frag), &_frag);
 57         if (fh == NULL) {
 58                 *hotdrop = true;
 59                 return false;
 60         }
 61 
 62         pr_debug("INFO %04X ", fh->frag_off);
 63         pr_debug("OFFSET %04X ", ntohs(fh->frag_off) & ~0x7);
 64         pr_debug("RES %02X %04X", fh->reserved, ntohs(fh->frag_off) & 0x6);
 65         pr_debug("MF %04X ", fh->frag_off & htons(IP6_MF));
 66         pr_debug("ID %u %08X\n", ntohl(fh->identification),
 67                  ntohl(fh->identification));
 68 
 69         pr_debug("IPv6 FRAG id %02X ",
 70                  id_match(fraginfo->ids[0], fraginfo->ids[1],
 71                           ntohl(fh->identification),
 72                           !!(fraginfo->invflags & IP6T_FRAG_INV_IDS)));
 73         pr_debug("res %02X %02X%04X %02X ",
 74                  fraginfo->flags & IP6T_FRAG_RES, fh->reserved,
 75                  ntohs(fh->frag_off) & 0x6,
 76                  !((fraginfo->flags & IP6T_FRAG_RES)
 77                    && (fh->reserved || (ntohs(fh->frag_off) & 0x06))));
 78         pr_debug("first %02X %02X %02X ",
 79                  fraginfo->flags & IP6T_FRAG_FST,
 80                  ntohs(fh->frag_off) & ~0x7,
 81                  !((fraginfo->flags & IP6T_FRAG_FST)
 82                    && (ntohs(fh->frag_off) & ~0x7)));
 83         pr_debug("mf %02X %02X %02X ",
 84                  fraginfo->flags & IP6T_FRAG_MF,
 85                  ntohs(fh->frag_off) & IP6_MF,
 86                  !((fraginfo->flags & IP6T_FRAG_MF)
 87                    && !((ntohs(fh->frag_off) & IP6_MF))));
 88         pr_debug("last %02X %02X %02X\n",
 89                  fraginfo->flags & IP6T_FRAG_NMF,
 90                  ntohs(fh->frag_off) & IP6_MF,
 91                  !((fraginfo->flags & IP6T_FRAG_NMF)
 92                    && (ntohs(fh->frag_off) & IP6_MF)));
 93 
 94         return (fh != NULL)
 95                &&
 96                id_match(fraginfo->ids[0], fraginfo->ids[1],
 97                         ntohl(fh->identification),
 98                         !!(fraginfo->invflags & IP6T_FRAG_INV_IDS))
 99                &&
100                !((fraginfo->flags & IP6T_FRAG_RES)
101                  && (fh->reserved || (ntohs(fh->frag_off) & 0x6)))
102                &&
103                !((fraginfo->flags & IP6T_FRAG_FST)
104                  && (ntohs(fh->frag_off) & ~0x7))
105                &&
106                !((fraginfo->flags & IP6T_FRAG_MF)
107                  && !(ntohs(fh->frag_off) & IP6_MF))
108                &&
109                !((fraginfo->flags & IP6T_FRAG_NMF)
110                  && (ntohs(fh->frag_off) & IP6_MF));
111 }
112 
113 /* Called when user tries to insert an entry of this type. */
114 static bool
115 frag_mt6_check(const char *tablename, const void *ip,
116                const struct xt_match *match, void *matchinfo,
117                unsigned int hook_mask)
118 {
119         const struct ip6t_frag *fraginfo = matchinfo;
120 
121         if (fraginfo->invflags & ~IP6T_FRAG_INV_MASK) {
122                 pr_debug("ip6t_frag: unknown flags %X\n", fraginfo->invflags);
123                 return false;
124         }
125         return true;
126 }
127 
128 static struct xt_match frag_mt6_reg __read_mostly = {
129         .name           = "frag",
130         .family         = AF_INET6,
131         .match          = frag_mt6,
132         .matchsize      = sizeof(struct ip6t_frag),
133         .checkentry     = frag_mt6_check,
134         .me             = THIS_MODULE,
135 };
136 
137 static int __init frag_mt6_init(void)
138 {
139         return xt_register_match(&frag_mt6_reg);
140 }
141 
142 static void __exit frag_mt6_exit(void)
143 {
144         xt_unregister_match(&frag_mt6_reg);
145 }
146 
147 module_init(frag_mt6_init);
148 module_exit(frag_mt6_exit);
149 
  This page was automatically generated by the LXR engine.