cregit-Linux how code gets into the kernel

Release 4.11 net/bridge/netfilter/ebt_stp.c

/*
 *  ebt_stp
 *
 *      Authors:
 *      Bart De Schuymer <bdschuym@pandora.be>
 *      Stephen Hemminger <shemminger@osdl.org>
 *
 *  July, 2003
 */
#include <linux/etherdevice.h>
#include <linux/module.h>
#include <linux/netfilter/x_tables.h>
#include <linux/netfilter_bridge/ebtables.h>
#include <linux/netfilter_bridge/ebt_stp.h>


#define BPDU_TYPE_CONFIG 0

#define BPDU_TYPE_TCN 0x80


struct stp_header {
	
u8 dsap;
	
u8 ssap;
	
u8 ctrl;
	
u8 pid;
	
u8 vers;
	
u8 type;
};


struct stp_config_pdu {
	
u8 flags;
	
u8 root[8];
	
u8 root_cost[4];
	
u8 sender[8];
	
u8 port[2];
	
u8 msg_age[2];
	
u8 max_age[2];
	
u8 hello_time[2];
	
u8 forward_delay[2];
};


#define NR16(p) (p[0] << 8 | p[1])

#define NR32(p) ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3])


static bool ebt_filter_config(const struct ebt_stp_info *info, const struct stp_config_pdu *stpc) { const struct ebt_stp_config_info *c; u16 v16; u32 v32; c = &info->config; if ((info->bitmask & EBT_STP_FLAGS) && NF_INVF(info, EBT_STP_FLAGS, c->flags != stpc->flags)) return false; if (info->bitmask & EBT_STP_ROOTPRIO) { v16 = NR16(stpc->root); if (NF_INVF(info, EBT_STP_ROOTPRIO, v16 < c->root_priol || v16 > c->root_priou)) return false; } if (info->bitmask & EBT_STP_ROOTADDR) { if (NF_INVF(info, EBT_STP_ROOTADDR, !ether_addr_equal_masked(&stpc->root[2], c->root_addr, c->root_addrmsk))) return false; } if (info->bitmask & EBT_STP_ROOTCOST) { v32 = NR32(stpc->root_cost); if (NF_INVF(info, EBT_STP_ROOTCOST, v32 < c->root_costl || v32 > c->root_costu)) return false; } if (info->bitmask & EBT_STP_SENDERPRIO) { v16 = NR16(stpc->sender); if (NF_INVF(info, EBT_STP_SENDERPRIO, v16 < c->sender_priol || v16 > c->sender_priou)) return false; } if (info->bitmask & EBT_STP_SENDERADDR) { if (NF_INVF(info, EBT_STP_SENDERADDR, !ether_addr_equal_masked(&stpc->sender[2], c->sender_addr, c->sender_addrmsk))) return false; } if (info->bitmask & EBT_STP_PORT) { v16 = NR16(stpc->port); if (NF_INVF(info, EBT_STP_PORT, v16 < c->portl || v16 > c->portu)) return false; } if (info->bitmask & EBT_STP_MSGAGE) { v16 = NR16(stpc->msg_age); if (NF_INVF(info, EBT_STP_MSGAGE, v16 < c->msg_agel || v16 > c->msg_ageu)) return false; } if (info->bitmask & EBT_STP_MAXAGE) { v16 = NR16(stpc->max_age); if (NF_INVF(info, EBT_STP_MAXAGE, v16 < c->max_agel || v16 > c->max_ageu)) return false; } if (info->bitmask & EBT_STP_HELLOTIME) { v16 = NR16(stpc->hello_time); if (NF_INVF(info, EBT_STP_HELLOTIME, v16 < c->hello_timel || v16 > c->hello_timeu)) return false; } if (info->bitmask & EBT_STP_FWDD) { v16 = NR16(stpc->forward_delay); if (NF_INVF(info, EBT_STP_FWDD, v16 < c->forward_delayl || v16 > c->forward_delayu)) return false; } return true; }

Contributors

PersonTokensPropCommitsCommitProp
Bart De Schuymer40381.25%116.67%
Joe Perches7515.12%233.33%
Jan Engelhardt163.23%233.33%
Tobin C Harding20.40%116.67%
Total496100.00%6100.00%


static bool ebt_stp_mt(const struct sk_buff *skb, struct xt_action_param *par) { const struct ebt_stp_info *info = par->matchinfo; const struct stp_header *sp; struct stp_header _stph; const u8 header[6] = {0x42, 0x42, 0x03, 0x00, 0x00, 0x00}; sp = skb_header_pointer(skb, 0, sizeof(_stph), &_stph); if (sp == NULL) return false; /* The stp code only considers these */ if (memcmp(sp, header, sizeof(header))) return false; if ((info->bitmask & EBT_STP_TYPE) && NF_INVF(info, EBT_STP_TYPE, info->type != sp->type)) return false; if (sp->type == BPDU_TYPE_CONFIG && info->bitmask & EBT_STP_CONFIG_MASK) { const struct stp_config_pdu *st; struct stp_config_pdu _stpc; st = skb_header_pointer(skb, sizeof(_stph), sizeof(_stpc), &_stpc); if (st == NULL) return false; return ebt_filter_config(info, st); } return true; }

Contributors

PersonTokensPropCommitsCommitProp
Bart De Schuymer12764.80%111.11%
David S. Miller3718.88%111.11%
Jan Engelhardt2412.24%555.56%
Joe Perches73.57%111.11%
Tobin C Harding10.51%111.11%
Total196100.00%9100.00%


static int ebt_stp_mt_check(const struct xt_mtchk_param *par) { const struct ebt_stp_info *info = par->matchinfo; const u8 bridge_ula[6] = {0x01, 0x80, 0xc2, 0x00, 0x00, 0x00}; const u8 msk[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; const struct ebt_entry *e = par->entryinfo; if (info->bitmask & ~EBT_STP_MASK || info->invflags & ~EBT_STP_MASK || !(info->bitmask & EBT_STP_MASK)) return -EINVAL; /* Make sure the match only receives stp frames */ if (!par->nft_compat && (!ether_addr_equal(e->destmac, bridge_ula) || !ether_addr_equal(e->destmsk, msk) || !(e->bitmask & EBT_DESTMAC))) return -EINVAL; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Bart De Schuymer11174.50%111.11%
Jan Engelhardt2516.78%555.56%
Pablo Neira Ayuso74.70%111.11%
Joe Perches42.68%111.11%
Tobin C Harding21.34%111.11%
Total149100.00%9100.00%

static struct xt_match ebt_stp_mt_reg __read_mostly = { .name = "stp", .revision = 0, .family = NFPROTO_BRIDGE, .match = ebt_stp_mt, .checkentry = ebt_stp_mt_check, .matchsize = sizeof(struct ebt_stp_info), .me = THIS_MODULE, };
static int __init ebt_stp_init(void) { return xt_register_match(&ebt_stp_mt_reg); }

Contributors

PersonTokensPropCommitsCommitProp
Bart De Schuymer1381.25%133.33%
Jan Engelhardt212.50%133.33%
Andrew Morton16.25%133.33%
Total16100.00%3100.00%


static void __exit ebt_stp_fini(void) { xt_unregister_match(&ebt_stp_mt_reg); }

Contributors

PersonTokensPropCommitsCommitProp
Bart De Schuymer1280.00%133.33%
Jan Engelhardt213.33%133.33%
Andrew Morton16.67%133.33%
Total15100.00%3100.00%

module_init(ebt_stp_init); module_exit(ebt_stp_fini); MODULE_DESCRIPTION("Ebtables: Spanning Tree Protocol packet match"); MODULE_LICENSE("GPL");

Overall Contributors

PersonTokensPropCommitsCommitProp
Bart De Schuymer79375.09%14.55%
Jan Engelhardt10710.13%1359.09%
Joe Perches868.14%313.64%
David S. Miller393.69%29.09%
Tobin C Harding201.89%14.55%
Pablo Neira Ayuso70.66%14.55%
Andrew Morton40.38%14.55%
Total1056100.00%22100.00%
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.