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

TOMOYO Linux Cross Reference
Linux/net/bridge/netfilter/ebt_arp.c

Version: ~ [ linux-5.12-rc7 ] ~ [ linux-5.11.13 ] ~ [ linux-5.10.29 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.111 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.186 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.230 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.266 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.266 ] ~ [ 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 /*
  2  *  ebt_arp
  3  *
  4  *      Authors:
  5  *      Bart De Schuymer <bdschuym@pandora.be>
  6  *      Tim Gardner <timg@tpi.com>
  7  *
  8  *  April, 2002
  9  *
 10  */
 11 #include <linux/if_arp.h>
 12 #include <linux/if_ether.h>
 13 #include <linux/module.h>
 14 #include <linux/netfilter/x_tables.h>
 15 #include <linux/netfilter_bridge/ebtables.h>
 16 #include <linux/netfilter_bridge/ebt_arp.h>
 17 
 18 static bool
 19 ebt_arp_mt(const struct sk_buff *skb, struct xt_action_param *par)
 20 {
 21         const struct ebt_arp_info *info = par->matchinfo;
 22         const struct arphdr *ah;
 23         struct arphdr _arph;
 24 
 25         ah = skb_header_pointer(skb, 0, sizeof(_arph), &_arph);
 26         if (ah == NULL)
 27                 return false;
 28         if ((info->bitmask & EBT_ARP_OPCODE) &&
 29             NF_INVF(info, EBT_ARP_OPCODE, info->opcode != ah->ar_op))
 30                 return false;
 31         if ((info->bitmask & EBT_ARP_HTYPE) &&
 32             NF_INVF(info, EBT_ARP_HTYPE, info->htype != ah->ar_hrd))
 33                 return false;
 34         if ((info->bitmask & EBT_ARP_PTYPE) &&
 35             NF_INVF(info, EBT_ARP_PTYPE, info->ptype != ah->ar_pro))
 36                 return false;
 37 
 38         if (info->bitmask & (EBT_ARP_SRC_IP | EBT_ARP_DST_IP | EBT_ARP_GRAT)) {
 39                 const __be32 *sap, *dap;
 40                 __be32 saddr, daddr;
 41 
 42                 if (ah->ar_pln != sizeof(__be32) || ah->ar_pro != htons(ETH_P_IP))
 43                         return false;
 44                 sap = skb_header_pointer(skb, sizeof(struct arphdr) +
 45                                         ah->ar_hln, sizeof(saddr),
 46                                         &saddr);
 47                 if (sap == NULL)
 48                         return false;
 49                 dap = skb_header_pointer(skb, sizeof(struct arphdr) +
 50                                         2*ah->ar_hln+sizeof(saddr),
 51                                         sizeof(daddr), &daddr);
 52                 if (dap == NULL)
 53                         return false;
 54                 if ((info->bitmask & EBT_ARP_SRC_IP) &&
 55                     NF_INVF(info, EBT_ARP_SRC_IP,
 56                             info->saddr != (*sap & info->smsk)))
 57                         return false;
 58                 if ((info->bitmask & EBT_ARP_DST_IP) &&
 59                     NF_INVF(info, EBT_ARP_DST_IP,
 60                             info->daddr != (*dap & info->dmsk)))
 61                         return false;
 62                 if ((info->bitmask & EBT_ARP_GRAT) &&
 63                     NF_INVF(info, EBT_ARP_GRAT, *dap != *sap))
 64                         return false;
 65         }
 66 
 67         if (info->bitmask & (EBT_ARP_SRC_MAC | EBT_ARP_DST_MAC)) {
 68                 const unsigned char *mp;
 69                 unsigned char _mac[ETH_ALEN];
 70 
 71                 if (ah->ar_hln != ETH_ALEN || ah->ar_hrd != htons(ARPHRD_ETHER))
 72                         return false;
 73                 if (info->bitmask & EBT_ARP_SRC_MAC) {
 74                         mp = skb_header_pointer(skb, sizeof(struct arphdr),
 75                                                 sizeof(_mac), &_mac);
 76                         if (mp == NULL)
 77                                 return false;
 78                         if (NF_INVF(info, EBT_ARP_SRC_MAC,
 79                                     !ether_addr_equal_masked(mp, info->smaddr,
 80                                                              info->smmsk)))
 81                                 return false;
 82                 }
 83 
 84                 if (info->bitmask & EBT_ARP_DST_MAC) {
 85                         mp = skb_header_pointer(skb, sizeof(struct arphdr) +
 86                                                 ah->ar_hln + ah->ar_pln,
 87                                                 sizeof(_mac), &_mac);
 88                         if (mp == NULL)
 89                                 return false;
 90                         if (NF_INVF(info, EBT_ARP_DST_MAC,
 91                                     !ether_addr_equal_masked(mp, info->dmaddr,
 92                                                              info->dmmsk)))
 93                                 return false;
 94                 }
 95         }
 96 
 97         return true;
 98 }
 99 
100 static int ebt_arp_mt_check(const struct xt_mtchk_param *par)
101 {
102         const struct ebt_arp_info *info = par->matchinfo;
103         const struct ebt_entry *e = par->entryinfo;
104 
105         if ((e->ethproto != htons(ETH_P_ARP) &&
106            e->ethproto != htons(ETH_P_RARP)) ||
107            e->invflags & EBT_IPROTO)
108                 return -EINVAL;
109         if (info->bitmask & ~EBT_ARP_MASK || info->invflags & ~EBT_ARP_MASK)
110                 return -EINVAL;
111         return 0;
112 }
113 
114 static struct xt_match ebt_arp_mt_reg __read_mostly = {
115         .name           = "arp",
116         .revision       = 0,
117         .family         = NFPROTO_BRIDGE,
118         .match          = ebt_arp_mt,
119         .checkentry     = ebt_arp_mt_check,
120         .matchsize      = sizeof(struct ebt_arp_info),
121         .me             = THIS_MODULE,
122 };
123 
124 static int __init ebt_arp_init(void)
125 {
126         return xt_register_match(&ebt_arp_mt_reg);
127 }
128 
129 static void __exit ebt_arp_fini(void)
130 {
131         xt_unregister_match(&ebt_arp_mt_reg);
132 }
133 
134 module_init(ebt_arp_init);
135 module_exit(ebt_arp_fini);
136 MODULE_DESCRIPTION("Ebtables: ARP protocol packet match");
137 MODULE_LICENSE("GPL");
138 

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