1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081
|
diff -uNr linux-2.2.13-vanilla/include/linux/netdevice.h linux/include/linux/netdevice.h
--- linux-2.2.13-vanilla/include/linux/netdevice.h Thu Aug 26 12:29:53 1999
+++ linux/include/linux/netdevice.h Wed Nov 10 09:06:54 1999
@@ -266,6 +266,9 @@
struct Qdisc *qdisc_list;
unsigned long tx_queue_len; /* Max frames per queue allowed */
+ /* Bridge stuff */
+ int bridge_port_id;
+
/* Pointers to interface service routines. */
int (*open)(struct device *dev);
int (*stop)(struct device *dev);
diff -uNr linux-2.2.13-vanilla/include/net/br.h linux/include/net/br.h
--- linux-2.2.13-vanilla/include/net/br.h Tue Aug 10 07:04:57 1999
+++ linux/include/net/br.h Wed Nov 10 09:06:54 1999
@@ -19,7 +19,16 @@
#define Forwarding 3 /* (4 4 4) */
#define Blocking 4 /* (4.4.1) */
-#define No_of_ports 8
+
+/* MAG Yich! Easiest way of giving a configurable number of ports
+ * If you want more than 32, change BR_MAX_PORTS and recompile brcfg!
+ */
+#define BR_MAX_PORTS (32)
+#if CONFIG_BRIDGE_NUM_PORTS > BR_MAX_PORTS
+#undef CONFIG_BRIDGE_NUM_PORTS
+#define CONFIG_BRIDGE_NUM_PORTS BR_MAX_PORTS
+#endif
+#define No_of_ports CONFIG_BRIDGE_NUM_PORTS
/* arbitrary choice, to allow the code below to compile */
#define All_ports (No_of_ports + 1)
@@ -147,6 +156,7 @@
unsigned int top_change; /* (4.5.3.12) */
unsigned short topology_change_time; /* (4.5.3.13) */
unsigned short hold_time; /* (4.5.3.14) */
+ unsigned int instance;
} Bridge_data;
/** Port Parameters (4.5.5) **/
@@ -160,7 +170,9 @@
unsigned short designated_port; /* (4.5.5.7) */
unsigned int top_change_ack; /* (4.5.5.8) */
unsigned int config_pending; /* (4.5.5.9) */
- struct device *dev;
+ bridge_id_t ifmac;
+ char ifname[IFNAMSIZ]; /* Make life easier for brcfg */
+ struct device *dev;
struct fdb *fdb; /* head of per port fdb chain */
} Port_data;
@@ -245,13 +257,14 @@
struct br_stat {
unsigned int flags;
Bridge_data bridge_data;
- Port_data port_data[No_of_ports];
unsigned int policy;
unsigned int exempt_protocols;
unsigned short protocols[BR_MAX_PROTOCOLS];
unsigned short prot_id[BR_MAX_PROT_STATS]; /* Protocol encountered */
unsigned int prot_counter[BR_MAX_PROT_STATS]; /* How many packets ? */
br_stats_counter packet_cnts;
+ unsigned int num_ports;
+ Port_data port_data[BR_MAX_PORTS + 1];
};
/* defined flags for br_stat.flags */
@@ -274,7 +287,7 @@
#define BRCMD_SET_BRIDGE_PRIORITY 5 /* arg1 = priority */
#define BRCMD_SET_PORT_PRIORITY 6 /* arg1 = port, arg2 = priority */
#define BRCMD_SET_PATH_COST 7 /* arg1 = port, arg2 = cost */
-#define BRCMD_DISPLAY_FDB 8 /* arg1 = port */
+#define BRCMD_DISPLAY_FDB 8
#define BRCMD_ENABLE_DEBUG 9
#define BRCMD_DISABLE_DEBUG 10
#define BRCMD_SET_POLICY 11 /* arg1 = default policy (1==bridge all) */
@@ -283,14 +296,19 @@
#define BRCMD_DISABLE_PROT_STATS 14
#define BRCMD_ZERO_PROT_STATS 15
#define BRCMD_TOGGLE_STP 16
+#define BRCMD_IF_ENABLE 17 /* arg1 = if_index */
+#define BRCMD_IF_DISABLE 18 /* arg1 = if_index */
+#define BRCMD_SET_IF_PRIORITY 19 /* arg1 = if_index, arg2 = priority */
+#define BRCMD_SET_IF_PATH_COST 20 /* arg1 = if_index, arg2 = cost */
/* prototypes of exported bridging functions... */
+#ifdef __KERNEL__
void br_init(void);
int br_receive_frame(struct sk_buff *skb); /* 3.5 */
int br_tx_frame(struct sk_buff *skb);
+int brg_init(void);
int br_ioctl(unsigned int cmd, void *arg);
-int br_protocol_ok(unsigned short protocol);
void requeue_fdb(struct fdb *node, int new_port);
struct fdb *br_avl_find_addr(unsigned char addr[6]);
@@ -298,8 +316,15 @@
void sprintf_avl (char **pbuffer, struct fdb * tree, off_t *pos,int* len, off_t offset, int length);
int br_tree_get_info(char *buffer, char **start, off_t offset, int length, int dummy);
void br_avl_delete_by_port(int port);
+int br_call_bridge(struct sk_buff *skb, unsigned short type);
+void br_spacedevice_register(void);
+
/* externs */
extern struct br_stat br_stats;
extern Port_data port_info[];
+#endif
+
+
+
diff -uNr linux-2.2.13-vanilla/net/Config.in linux/net/Config.in
--- linux-2.2.13-vanilla/net/Config.in Fri Feb 26 07:46:47 1999
+++ linux/net/Config.in Wed Nov 10 09:06:55 1999
@@ -39,6 +39,9 @@
tristate 'CCITT X.25 Packet Layer (EXPERIMENTAL)' CONFIG_X25
tristate 'LAPB Data Link Driver (EXPERIMENTAL)' CONFIG_LAPB
bool 'Bridging (EXPERIMENTAL)' CONFIG_BRIDGE
+ if [ "$CONFIG_BRIDGE" != "n" ]; then
+ int ' Maximum number of bridged interfaces' CONFIG_BRIDGE_NUM_PORTS 8
+ fi
bool '802.2 LLC (EXPERIMENTAL)' CONFIG_LLC
# if [ "$CONFIG_LLC" = "y" ]; then
# bool 'Netbeui (EXPERIMENTAL)' CONFIG_NETBEUI
diff -uNr linux-2.2.13-vanilla/net/bridge/br.c linux/net/bridge/br.c
--- linux-2.2.13-vanilla/net/bridge/br.c Tue Aug 10 07:05:05 1999
+++ linux/net/bridge/br.c Wed Nov 10 09:09:25 1999
@@ -40,10 +40,19 @@
* so blame me first if its broken ;)
*
* Robert Pintarelli: fixed bug in bpdu time values
+ *
+ * Matthew Grant: start ports disabled.
+ * auto-promiscuous mode on port enable/disable
+ * fleshed out interface event handling, interfaces
+ * now register with bridge on module load as well as ifup
+ * port control ioctls with ifindex support
+ * brg0 logical ethernet interface
+ * reworked brcfg to take interface arguments
+ * added support for changing the hardware address
+ * generally made bridge a lot more usable.
*
* Todo:
- * Don't bring up devices automatically. Start ports disabled
- * and use a netlink notifier so a daemon can maintain the bridge
+ * Use a netlink notifier so a daemon can maintain the bridge
* port group (could we also do multiple groups ????).
* A nice /proc file interface.
* Put the path costs in the port info and devices.
@@ -53,6 +62,7 @@
*/
#include <linux/config.h>
+#include <linux/module.h>
#include <linux/errno.h>
#include <linux/types.h>
#include <linux/socket.h>
@@ -61,10 +71,13 @@
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/timer.h>
+#include <linux/malloc.h>
#include <linux/string.h>
#include <linux/net.h>
#include <linux/inet.h>
#include <linux/netdevice.h>
+#include <linux/inetdevice.h>
+#include <linux/etherdevice.h>
#include <linux/skbuff.h>
#include <linux/if_arp.h>
#include <linux/ip.h>
@@ -72,6 +85,7 @@
#include <linux/init.h>
#include <asm/uaccess.h>
#include <asm/system.h>
+#include <linux/rtnetlink.h>
#include <net/br.h>
#include <linux/proc_fs.h>
@@ -145,11 +159,20 @@
static int br_flood(struct sk_buff *skb, int port);
static int br_drop(struct sk_buff *skb);
static int br_learn(struct sk_buff *skb, int port); /* 3.8 */
+static int br_protocol_ok(unsigned short protocol);
+static int br_find_port(int ifindex);
+static void br_get_ifnames(void);
+static int brg_rx(struct sk_buff *skb, int port);
static unsigned char bridge_ula[ETH_ALEN] = { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x00 };
static Bridge_data bridge_info; /* (4.5.3) */
Port_data port_info[All_ports]; /* (4.5.5) */
+/* MAG: Maximum port registered - used to speed up flooding and to make
+ * have a large ports array more efficient
+ */
+static int max_port_used = 0;
+
/* JRP: fdb cache 1/port save kmalloc/kfree on every frame */
struct fdb *newfdb[All_ports];
int allocated_fdb_cnt = 0;
@@ -190,6 +213,30 @@
0
};
+
+/*
+ * the following data is for the bridge network device
+ */
+struct brg_if {
+ struct device dev;
+ char name[IFNAMSIZ];
+};
+static struct brg_if brg_if;
+
+/*
+ * Here to save linkage? problems
+ */
+
+static inline int find_port(struct device *dev)
+{
+ int i;
+
+ for (i = One; i <= No_of_ports; i++)
+ if (port_info[i].dev == dev)
+ return(i);
+ return(0);
+}
+
/*
* Implementation of Protocol specific bridging
*
@@ -202,7 +249,7 @@
/* Checks if that protocol type is to be bridged */
-int br_protocol_ok(unsigned short protocol)
+static int inline br_protocol_ok(unsigned short protocol)
{
unsigned x;
@@ -843,8 +890,14 @@
{ /* (4.8.1) */
int port_no;
- printk(KERN_INFO "NET4: Ethernet Bridge 005 for NET4.0\n");
+ printk(KERN_INFO "NET4: Ethernet Bridge 006 for NET4.0\n");
+
+ /* Set up brg device information */
+ bridge_info.instance = 0;
+ brg_init();
+ max_port_used = 0;
+
/*
* Form initial topology change time.
* The topology change timer is only used if this is the root bridge.
@@ -874,8 +927,8 @@
stop_topology_change_timer();
memset(newfdb, 0, sizeof(newfdb));
for (port_no = One; port_no <= No_of_ports; port_no++) { /* (4.8.1.4) */
- /* initial state = Enable */
- user_port_state[port_no] = ~Disabled;
+ /* initial state = Disable */
+ user_port_state[port_no] = Disabled;
port_priority[port_no] = 128;
br_init_port(port_no);
disable_port(port_no);
@@ -1205,7 +1258,7 @@
memcpy(eth->h_source, dev->dev_addr, ETH_ALEN);
if (br_stats.flags & BR_DEBUG)
- printk("send_%s_bpdu: port %i src %02x:%02x:%02x:%02x:%02x:%02x\n",
+ printk(KERN_DEBUG "send_%s_bpdu: port %i src %02x:%02x:%02x:%02x:%02x:%02x\n",
pdu_name,
port_no,
eth->h_source[0],
@@ -1306,6 +1359,9 @@
if (dev->flags & IFF_LOOPBACK)
return(NOTIFY_DONE);
+ if (dev == &brg_if.dev)
+ return(NOTIFY_DONE); /* Don't attach the brg device to a port! */
+
switch (event)
{
case NETDEV_DOWN:
@@ -1335,6 +1391,9 @@
{
port_info[i].dev = dev;
port_info[i].port_id = i;
+ dev->bridge_port_id = i;
+ if( i > max_port_used )
+ max_port_used = i;
/* set bridge addr from 1st device addr */
if (((htonl(bridge_info.bridge_id.BRIDGE_ID[0])&0xffff) == 0) &&
(bridge_info.bridge_id.BRIDGE_ID[1] == 0))
@@ -1344,7 +1403,10 @@
bridge_info.bridge_id.BRIDGE_PRIORITY = htons(32768);
set_bridge_priority(&bridge_info.bridge_id);
}
+ /* Add local MAC address */
br_add_local_mac(dev->dev_addr);
+ /* Save MAC address for latter change address events */
+ memcpy(port_info[i].ifmac.BRIDGE_ID_ULA, dev->dev_addr, 6);
if((br_stats.flags & BR_UP) &&
(user_port_state[i] != Disabled))
{
@@ -1362,19 +1424,116 @@
}
}
break;
+ case NETDEV_REGISTER:
+ if (br_stats.flags & BR_DEBUG)
+ printk(KERN_DEBUG "br_device_event: NETDEV_REGISTER...\n");
+ /* printk(KERN_ERR "br_device_event: NETDEV_REGISTER...\n"); */
+ /* printk(KERN_ERR "br_device_event: dev->type: 0x%X\n", dev->type); */
+ /* Only handle ethernet ports */
+ if(dev->type!=ARPHRD_ETHER && dev->type!=ARPHRD_LOOPBACK)
+ return NOTIFY_DONE;
+ /* printk(KERN_ERR "br_device_event: Looking for port...\n"); */
+ for (i = One; i <= No_of_ports; i++)
+ {
+ if (port_info[i].dev == NULL || port_info[i].dev == dev)
+ {
+ /* printk(KERN_ERR "br_device_event: Found port %d\n", i); */
+ port_info[i].dev = dev;
+ port_info[i].port_id = i;
+ dev->bridge_port_id = i;
+ if( i > max_port_used )
+ max_port_used = i;
+ /* handle local MAC address minuplations */
+ br_add_local_mac(dev->dev_addr);
+ memcpy(port_info[i].ifmac.BRIDGE_ID_ULA, dev->dev_addr, 6);
+ return NOTIFY_DONE;
+ break;
+ }
+ }
+ break;
case NETDEV_UNREGISTER:
if (br_stats.flags & BR_DEBUG)
printk(KERN_DEBUG "br_device_event: NETDEV_UNREGISTER...\n");
i = find_port(dev);
if (i > 0) {
br_avl_delete_by_port(i);
+ memset(port_info[i].ifmac.BRIDGE_ID_ULA, 0, 6);
port_info[i].dev = NULL;
}
break;
+ case NETDEV_CHANGEADDR:
+ if (br_stats.flags & BR_DEBUG)
+ printk(KERN_DEBUG "br_device_event: NETDEV_CHANGEADDR...\n");
+ i = find_port(dev);
+ if (i <= 0)
+ break;
+ if (memcmp(port_info[i].ifmac.BRIDGE_ID_ULA, dev->dev_addr, 6) != 0)
+ break; /* Don't worry about a change of hardware broadcast address! */
+ if (dev->start) {
+ printk(KERN_CRIT "br_device_event: NETDEV_CHANGEADDR on busy device %s - FIX DRIVER!\n",
+ dev->name);
+ /* return NOTIFY_BAD; It SHOULD be this, but I want to be friendly... */
+ return NOTIFY_DONE;
+ }
+ br_avl_delete_by_port(i);
+ memset(port_info[i].ifmac.BRIDGE_ID_ULA, 0, 6);
+ break;
}
return NOTIFY_DONE;
}
+/* Routine to loop over device list and register
+ * interfaces to bridge. Called from last part of net_dev_init just before
+ * bootp/rarp interface setup
+ */
+void br_spacedevice_register(void)
+{
+ struct device *dev;
+ for( dev = dev_base; dev != NULL; dev = dev->next)
+ {
+ br_device_event(NULL, NETDEV_REGISTER, dev);
+ }
+}
+
+
+/* This is for SPEED in the kernel in net_bh.c */
+
+int br_call_bridge(struct sk_buff *skb, unsigned short type)
+{
+ int port;
+ struct device *dev;
+
+#if 0 /* Checked first in handle_bridge to save expense of function call */
+ if(!(br_stats.flags & BR_UP))
+ return 0;
+#endif
+
+ dev = skb->dev;
+ port = dev->bridge_port_id;
+
+ if(!port)
+ return 0;
+
+ /* Sanity - make sure we are not leaping off into fairy space! */
+ if ( port < 0 || port > max_port_used || port_info[port].dev != dev) {
+ if (net_ratelimit())
+ printk(KERN_CRIT "br_call_bridge: device %s has invalid port ID %d!\n",
+ dev->name,
+ dev->bridge_port_id);
+ return 0;
+ }
+
+ if(user_port_state[port] == Disabled)
+ return 0;
+
+ if (!br_protocol_ok(ntohs(type)))
+ return 0;
+
+ return 1;
+
+}
+
+
/*
* following routine is called when a frame is received
* from an interface, it returns 1 when it consumes the
@@ -1386,6 +1545,7 @@
int port;
Port_data *p;
struct ethhdr *eth;
+ struct device *dev;
/* sanity */
if (!skb) {
@@ -1393,17 +1553,27 @@
return(1);
}
+ dev = skb->dev;
+
skb->pkt_bridged = IS_BRIDGED;
/* check for loopback */
- if (skb->dev->flags & IFF_LOOPBACK)
+ if (dev->flags & IFF_LOOPBACK)
return 0 ;
- port = find_port(skb->dev);
+#if 0
+ port = find_port(dev);
+#else
+ port = dev->bridge_port_id;
+#endif
if(!port)
return 0;
+ /* Hand off to brg_rx BEFORE we screw up the skb */
+ if(brg_rx(skb, port))
+ return(1);
+
skb->nh.raw = skb->mac.raw;
eth = skb->mac.ethernet;
p = &port_info[port];
@@ -1512,7 +1682,7 @@
eth = skb->mac.ethernet;
port = 0; /* an impossible port (locally generated) */
if (br_stats.flags & BR_DEBUG)
- printk("br_tx_fr : port %i src %02x:%02x:%02x:%02x:%02x:%02x"
+ printk(KERN_DEBUG "br_tx_fr : port %i src %02x:%02x:%02x:%02x:%02x:%02x"
" dest %02x:%02x:%02x:%02x:%02x:%02x\n",
port,
eth->h_source[0],
@@ -1750,7 +1920,7 @@
/* timer expired, invalidate entry */
f->flags &= ~FDB_ENT_VALID;
if (br_stats.flags & BR_DEBUG)
- printk("fdb entry expired...\n");
+ printk(KERN_DEBUG "fdb entry expired...\n");
/*
* Send flood and drop original
*/
@@ -1792,7 +1962,7 @@
/* timer expired, invalidate entry */
f->flags &= ~FDB_ENT_VALID;
if (br_stats.flags & BR_DEBUG)
- printk("fdb entry expired...\n");
+ printk(KERN_DEBUG "fdb entry expired...\n");
++br_stats_cnt.drop_same_port_aged;
}
else ++br_stats_cnt.drop_same_port;
@@ -1819,6 +1989,9 @@
{
if (i == port) /* don't send back where we got it */
continue;
+ if (i > max_port_used)
+ /* Don't go scanning empty port entries */
+ break;
if (port_info[i].state == Forwarding)
{
nskb = skb_clone(skb, GFP_ATOMIC);
@@ -1831,7 +2004,7 @@
/* To get here we must have done ARP already,
or have a received valid MAC header */
-/* printk("Flood to port %d\n",i);*/
+/* printk(KERN_DEBUG "Flood to port %d\n",i);*/
nskb->nh.raw = nskb->data + ETH_HLEN;
nskb->priority = 1;
dev_queue_xmit(nskb);
@@ -1840,16 +2013,6 @@
return(0);
}
-static int find_port(struct device *dev)
-{
- int i;
-
- for (i = One; i <= No_of_ports; i++)
- if (port_info[i].dev == dev)
- return(i);
- return(0);
-}
-
/*
* FIXME: This needs to come from the device structs, eg for
* 10,100,1Gbit ethernet.
@@ -1956,17 +2119,58 @@
return fdbis;
}
+
+/* Fill in interface names in port_info structure
+ */
+static void br_get_ifnames(void) {
+ int i;
+
+ for(i=One;i<=No_of_ports; i++) {
+ /* memset IS needed. Kernel strncpy does NOT NULL terminate strings when limit
+ reached */
+ memset(port_info[i].ifname, 0, IFNAMSIZ);
+ if( port_info[i].dev == 0 )
+ continue;
+ strncpy(port_info[i].ifname, port_info[i].dev->name, IFNAMSIZ-1);
+ /* Being paranoid */
+ port_info[i].ifname[IFNAMSIZ-1] = '\0';
+ }
+}
+
+/* Given an interface index, loop over port array to see if configured. If
+ so, return port number, otherwise error */
+static int br_find_port(int ifindex)
+{
+ int i;
+
+ for(i=1; i <= No_of_ports; i++) {
+ if (port_info[i].dev == 0)
+ continue;
+ if (port_info[i].dev->ifindex == ifindex)
+ return(i);
+ }
+
+ return -EUNATCH; /* Tell me if this is incorrect error code for this case */
+}
+
+
int br_ioctl(unsigned int cmd, void *arg)
{
- int err, i;
+ int err, i, ifflags;
struct br_cf bcf;
bridge_id_t new_id;
-
+ struct device *dev;
+
switch(cmd)
{
case SIOCGIFBR: /* get bridging control blocks */
memcpy(&br_stats.bridge_data, &bridge_info, sizeof(Bridge_data));
- memcpy(&br_stats.port_data, &port_info, sizeof(Port_data)*No_of_ports);
+
+ /* Fill in interface names in port_info*/
+ br_get_ifnames();
+
+ br_stats.num_ports = No_of_ports;
+ memcpy(&br_stats.port_data, &port_info, sizeof(Port_data)*All_ports);
err = copy_to_user(arg, &br_stats, sizeof(struct br_stat));
if (err)
@@ -2032,16 +2236,28 @@
}
br_stats.flags ^= BR_STP_DISABLED;
break;
+ case BRCMD_IF_ENABLE:
+ bcf.arg1 = br_find_port(bcf.arg1);
+ if (bcf.arg1 < 0)
+ return(bcf.arg1);
case BRCMD_PORT_ENABLE:
if (port_info[bcf.arg1].dev == 0)
return(-EINVAL);
if (user_port_state[bcf.arg1] != Disabled)
return(-EALREADY);
printk(KERN_DEBUG "br: enabling port %i\n",bcf.arg1);
+ dev = port_info[bcf.arg1].dev;
+ ifflags = (dev->flags&~(IFF_PROMISC|IFF_ALLMULTI))
+ |(dev->gflags&(IFF_PROMISC|IFF_ALLMULTI));
+ dev_change_flags(dev, ifflags|IFF_PROMISC);
user_port_state[bcf.arg1] = ~Disabled;
if(br_stats.flags & BR_UP)
enable_port(bcf.arg1);
break;
+ case BRCMD_IF_DISABLE:
+ bcf.arg1 = br_find_port(bcf.arg1);
+ if (bcf.arg1 < 0)
+ return(bcf.arg1);
case BRCMD_PORT_DISABLE:
if (port_info[bcf.arg1].dev == 0)
return(-EINVAL);
@@ -2051,12 +2267,20 @@
user_port_state[bcf.arg1] = Disabled;
if(br_stats.flags & BR_UP)
disable_port(bcf.arg1);
+ dev = port_info[bcf.arg1].dev;
+ ifflags = (dev->flags&~(IFF_PROMISC|IFF_ALLMULTI))
+ |(dev->gflags&(IFF_PROMISC|IFF_ALLMULTI));
+ dev_change_flags(port_info[bcf.arg1].dev, ifflags & ~IFF_PROMISC);
break;
case BRCMD_SET_BRIDGE_PRIORITY:
new_id = bridge_info.bridge_id;
new_id.BRIDGE_PRIORITY = htons(bcf.arg1);
set_bridge_priority(&new_id);
break;
+ case BRCMD_SET_IF_PRIORITY:
+ bcf.arg1 = br_find_port(bcf.arg1);
+ if (bcf.arg1 < 0)
+ return(bcf.arg1);
case BRCMD_SET_PORT_PRIORITY:
if((port_info[bcf.arg1].dev == 0)
|| (bcf.arg2 & ~0xff))
@@ -2064,6 +2288,10 @@
port_priority[bcf.arg1] = bcf.arg2;
set_port_priority(bcf.arg1);
break;
+ case BRCMD_SET_IF_PATH_COST:
+ bcf.arg1 = br_find_port(bcf.arg1);
+ if (bcf.arg1 < 0)
+ return(bcf.arg1);
case BRCMD_SET_PATH_COST:
if (port_info[bcf.arg1].dev == 0)
return(-EINVAL);
@@ -2145,3 +2373,377 @@
}
return(0);
}
+
+
+
+
+/* --------------------------------------------------------------------------------
+ *
+ *
+ * Bridge network device here for future modularization - device structures
+ * must be 'static' inside bridge instance
+ * Modelled after sch_teql.c
+ *
+ */
+
+
+
+/*
+ * Index to functions.
+ */
+
+int brg_probe(struct device *dev);
+static int brg_open(struct device *dev);
+static int brg_start_xmit(struct sk_buff *skb, struct device *dev);
+static int brg_close(struct device *dev);
+static struct net_device_stats *brg_get_stats(struct device *dev);
+static void brg_set_multicast_list(struct device *dev);
+
+/*
+ * Board-specific info in dev->priv.
+ */
+
+struct net_local
+{
+ __u32 groups;
+ struct net_device_stats stats;
+};
+
+
+
+
+/*
+ * To call this a probe is a bit misleading, however for real
+ * hardware it would have to check what was present.
+ */
+
+__initfunc(int brg_probe(struct device *dev))
+{
+ unsigned int bogomips;
+ struct timeval utime;
+
+ printk(KERN_INFO "%s: network interface for Ethernet Bridge 006/NET4.0\n", dev->name);
+
+ /*
+ * Initialize the device structure.
+ */
+
+ dev->priv = kmalloc(sizeof(struct net_local), GFP_KERNEL);
+ if (dev->priv == NULL)
+ return -ENOMEM;
+ memset(dev->priv, 0, sizeof(struct net_local));
+
+ /* Set up MAC address based on BogoMIPs figure for first CPU and time
+ */
+ bogomips = (boot_cpu_data.loops_per_sec+2500)/500000 ;
+ get_fast_time(&utime);
+
+ /* Ummmm.... YES! */
+ dev->dev_addr[0] = '\xFE';
+ dev->dev_addr[1] = '\xFD';
+ dev->dev_addr[2] = (bridge_info.instance & 0x0F) << 4;
+ dev->dev_addr[2] |= ((utime.tv_sec & 0x000F0000) >> 16);
+ dev->dev_addr[3] = bogomips & 0xFF;
+ dev->dev_addr[4] = (utime.tv_sec & 0x0000FF00) >> 8;
+ dev->dev_addr[5] = (utime.tv_sec & 0x000000FF);
+
+ printk(KERN_INFO "%s: generated MAC address %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
+ dev->name,
+ dev->dev_addr[0],
+ dev->dev_addr[1],
+ dev->dev_addr[2],
+ dev->dev_addr[3],
+ dev->dev_addr[4],
+ dev->dev_addr[5]);
+
+
+ printk(KERN_INFO "%s: attached to bridge instance %lu\n", dev->name, dev->base_addr);
+
+ /*
+ * The brg specific entries in the device structure.
+ */
+
+ dev->open = brg_open;
+ dev->hard_start_xmit = brg_start_xmit;
+ dev->stop = brg_close;
+ dev->get_stats = brg_get_stats;
+ dev->set_multicast_list = brg_set_multicast_list;
+
+ /*
+ * Setup the generic properties
+ */
+
+ ether_setup(dev);
+
+ dev->tx_queue_len = 0;
+
+ return 0;
+}
+
+/*
+ * Open/initialize the board.
+ */
+
+static int brg_open(struct device *dev)
+{
+ if (br_stats.flags & BR_DEBUG)
+ printk(KERN_DEBUG "%s: Doing brg_open()...", dev->name);
+
+ if (memcmp(dev->dev_addr, "\x00\x00\x00\x00\x00\x00", ETH_ALEN) == 0)
+ return -EFAULT;
+
+ dev->start = 1;
+ dev->tbusy = 0;
+ return 0;
+}
+
+static unsigned brg_mc_hash(__u8 *dest)
+{
+ unsigned idx = 0;
+ idx ^= dest[0];
+ idx ^= dest[1];
+ idx ^= dest[2];
+ idx ^= dest[3];
+ idx ^= dest[4];
+ idx ^= dest[5];
+ return 1U << (idx&0x1F);
+}
+
+static void brg_set_multicast_list(struct device *dev)
+{
+ unsigned groups = ~0;
+ struct net_local *lp = (struct net_local *)dev->priv;
+
+ if (!(dev->flags&(IFF_PROMISC|IFF_ALLMULTI))) {
+ struct dev_mc_list *dmi;
+
+ groups = brg_mc_hash(dev->broadcast);
+
+ for (dmi=dev->mc_list; dmi; dmi=dmi->next) {
+ if (dmi->dmi_addrlen != 6)
+ continue;
+ groups |= brg_mc_hash(dmi->dmi_addr);
+ }
+ }
+ lp->groups = groups;
+}
+
+/*
+ * We transmit by throwing the packet at the bridge.
+ */
+
+static int brg_start_xmit(struct sk_buff *skb, struct device *dev)
+{
+ struct net_local *lp = (struct net_local *)dev->priv;
+ struct ethhdr *eth = (struct ethhdr*)skb->data;
+ int port;
+
+ /* Deal with the bridge being disabled */
+ if(!(br_stats.flags & BR_UP)) {
+ /* Either this */
+ /* lp->stats.tx_errors++; */ /* this condition is NOT an error */
+ /* or this (implied by RFC 2233) */
+ lp->stats.tx_dropped++;
+ dev_kfree_skb(skb);
+ return 0;
+ }
+
+ lp->stats.tx_bytes+=skb->len;
+ lp->stats.tx_packets++;
+
+#if 0
+ ++br_stats_cnt.port_not_disable;
+#endif
+ skb->mac.raw = skb->nh.raw = skb->data;
+ eth = skb->mac.ethernet;
+ port = 0; /* an impossible port (locally generated) */
+
+ if (br_stats.flags & BR_DEBUG)
+ printk(KERN_DEBUG "%s: brg_start_xmit - src %02x:%02x:%02x:%02x:%02x:%02x"
+ " dest %02x:%02x:%02x:%02x:%02x:%02x\n",
+ dev->name,
+ eth->h_source[0],
+ eth->h_source[1],
+ eth->h_source[2],
+ eth->h_source[3],
+ eth->h_source[4],
+ eth->h_source[5],
+ eth->h_dest[0],
+ eth->h_dest[1],
+ eth->h_dest[2],
+ eth->h_dest[3],
+ eth->h_dest[4],
+ eth->h_dest[5]);
+
+ /* Forward the packet ! */
+ if(br_forward(skb, port))
+ return(0);
+
+ /* Throw packet initially */
+ dev_kfree_skb(skb);
+ return 0;
+}
+
+
+/*
+ * The typical workload of the driver:
+ * Handle the ether interface interrupts.
+ *
+ * (In this case handle the packets posted from the bridge)
+ */
+
+static int brg_rx(struct sk_buff *skb, int port)
+{
+ struct device *dev = &brg_if.dev;
+ struct net_local *lp = (struct net_local *)dev->priv;
+ struct ethhdr *eth = (struct ethhdr*)(skb->data);
+ int len = skb->len;
+ int clone = 0;
+
+ if (br_stats.flags & BR_DEBUG)
+ printk(KERN_DEBUG "%s: brg_rx()\n", dev->name);
+
+ /* Get out of here if the bridge interface is not up
+ */
+ if(!(dev->flags & IFF_UP))
+ return(0);
+
+ /* Check that the port that this thing came off is in the forwarding state
+ * We sould only listen to the same address scope we will transmit to.
+ */
+ if(port_info[port].state != Forwarding)
+ return(0);
+
+ /* Is this for us? - broadcast/mulitcast/promiscuous packets need cloning,
+ * with uni-cast we eat the packet
+ */
+ clone = 0;
+ if (dev->flags & IFF_PROMISC) {
+ clone = 1;
+ }
+ else if (eth->h_dest[0]&1) {
+ if (!(dev->flags&(IFF_ALLMULTI))
+ && !(brg_mc_hash(eth->h_dest)&lp->groups))
+ return(0);
+ clone = 1;
+ }
+ else if (memcmp(eth->h_dest, dev->dev_addr, ETH_ALEN) != 0) {
+ return(0);
+ }
+
+ /* Clone things here - we want to be transparent before we check packet data
+ * integrity
+ */
+ if(clone) {
+ struct sk_buff *skb2 = skb;
+ skb = skb_clone(skb2, GFP_KERNEL);
+ if (skb == NULL) {
+ return(0);
+ }
+
+ }
+
+ /* Check packet length
+ */
+ if (len < 16) {
+ printk(KERN_DEBUG "%s : rx len = %d\n", dev->name, len);
+ kfree_skb(skb);
+ return(!clone);
+ }
+
+ if (br_stats.flags & BR_DEBUG)
+ printk(KERN_DEBUG "%s: brg_rx - src %02x:%02x:%02x:%02x:%02x:%02x"
+ " dest %02x:%02x:%02x:%02x:%02x:%02x\n",
+ dev->name,
+ eth->h_source[0],
+ eth->h_source[1],
+ eth->h_source[2],
+ eth->h_source[3],
+ eth->h_source[4],
+ eth->h_source[5],
+ eth->h_dest[0],
+ eth->h_dest[1],
+ eth->h_dest[2],
+ eth->h_dest[3],
+ eth->h_dest[4],
+ eth->h_dest[5]);
+
+ /* Do it */
+ skb->pkt_type = PACKET_HOST;
+ skb->dev = dev;
+ skb->protocol=eth_type_trans(skb,dev);
+ memset(skb->cb, 0, sizeof(skb->cb));
+ lp->stats.rx_packets++;
+ lp->stats.rx_bytes+=len;
+ netif_rx(skb);
+ return(!clone);
+}
+
+static int brg_close(struct device *dev)
+{
+ if (br_stats.flags & BR_DEBUG)
+ printk(KERN_DEBUG "%s: Shutting down.\n", dev->name);
+
+ dev->tbusy = 1;
+ dev->start = 0;
+
+ return 0;
+}
+
+static struct net_device_stats *brg_get_stats(struct device *dev)
+{
+ struct net_local *lp = (struct net_local *)dev->priv;
+ return &lp->stats;
+}
+
+/*
+ *
+ */
+
+__initfunc(int brg_init(void))
+{
+ int err;
+
+ memset(&brg_if, 0, sizeof(brg_if));
+
+ rtnl_lock();
+
+ brg_if.dev.base_addr = bridge_info.instance;
+ sprintf (brg_if.name, "brg%d", bridge_info.instance);
+ brg_if.dev.name = (void*)&brg_if.name;
+ if(dev_get(brg_if.name)) {
+ printk(KERN_INFO "%s already loaded.\n", brg_if.name);
+ return -EBUSY;
+ }
+ brg_if.dev.init = brg_probe;
+
+ err = register_netdevice(&brg_if.dev);
+ rtnl_unlock();
+ return err;
+}
+
+
+#if 0 /* Its here if we ever need it... */
+#ifdef MODULE
+
+void cleanup_module(void)
+{
+
+ /*
+ * Unregister the device
+ */
+ rtnl_lock();
+ unregister_netdevice(&the_master.dev);
+ rtnl_unlock();
+
+ /*
+ * Free up the private structure.
+ */
+
+ kfree(brg_if.dev.priv);
+ brg_if.dev.priv = NULL; /* gets re-allocated by brg_probe */
+}
+
+#endif /* MODULE */
+
+#endif
diff -uNr linux-2.2.13-vanilla/net/bridge/br_tree.c linux/net/bridge/br_tree.c
--- linux-2.2.13-vanilla/net/bridge/br_tree.c Mon Mar 8 12:25:23 1999
+++ linux/net/bridge/br_tree.c Wed Nov 10 09:06:55 1999
@@ -492,7 +492,8 @@
port_info[port].fdb = NULL;
/* remove the local mac too */
- next = br_avl_find_addr(port_info[port].dev->dev_addr);
+/* next = br_avl_find_addr(port_info[port].dev->dev_addr); */
+ next = br_avl_find_addr(port_info[port].ifmac.BRIDGE_ID_ULA);
if (next != NULL)
br_avl_remove(next);
diff -uNr linux-2.2.13-vanilla/net/core/dev.c linux/net/core/dev.c
--- linux-2.2.13-vanilla/net/core/dev.c Wed Oct 20 13:14:02 1999
+++ linux/net/core/dev.c Wed Nov 10 09:06:54 1999
@@ -796,7 +796,11 @@
#ifdef CONFIG_BRIDGE
static inline void handle_bridge(struct sk_buff *skb, unsigned short type)
{
- if (br_stats.flags & BR_UP && br_protocol_ok(ntohs(type)))
+ /*
+ * The br_stats.flags is checked here to save the expense of a
+ * function call.
+ */
+ if ((br_stats.flags & BR_UP) && br_call_bridge(skb, type))
{
/*
* We pass the bridge a complete frame. This means
@@ -820,7 +824,6 @@
}
#endif
-
/*
* When we are called the queue is ready to grab, the interrupts are
* on and hardware can interrupt and queue to the receive queue as we
@@ -2017,6 +2020,13 @@
dev_boot_phase = 0;
dev_mcast_init();
+
+#ifdef CONFIG_BRIDGE
+ /*
+ * Register any statically linked ethernet devices with the bridge
+ */
+ br_spacedevice_register();
+#endif
#ifdef CONFIG_IP_PNP
ip_auto_config();
|