Linux IGMP snooping Learning notes one of the corresponding data structures and initialization __html

Source: Internet
Author: User
Tags joins time interval


Data structure related to igmpsnooping

Multicast-related data structure mainly has three, the following analysis respectively:

1, struct net_bridge_mdb_htable

/* Multicast group database to publish, the structure of all multicast group database forwarding items through a hash array connected to the

struct net_bridge_mdb_htable

{

Structhlist_head *mhash; Hash array that will link all the net_bridge_mdb_entry together

Structrcu_head RCU;

Structnet_bridge_mdb_htable *old;

U32 size; The total number of all net_bridge_mdb_entry entries that exist in all hash lists in the hash array

U32 the maximum value of the Max;//hash array

U32 secret;

U32 ver;

};

2, Net_bridge_mdb_entry

/* A multicast group database forwarding item, describing the details of a multicast group.

struct Net_bridge_mdb_entry

{

Structhlist_node hlist[2];

Structhlist_node mglist;

Structnet_bridge *br;//Bridge

Structnet_bridge_port_group *ports;//

Structrcu_head RCU;

Structtimer_list timer;//Multicast Group database entry expiration timer, if timed out, the multicast port is removed from the multicast port list of the multicast group database entry

Structtimer_list query_timer;//Query Timing

__BE32 addr;//Multicast Group address

U32 queries_sent;

};

Where port points to all multicast ports that are joined to the multicast group addr

Mglist is used to connect the multicast group database forwarding entries created by the IGMP join message received via bridge BR

3, struct Net_bridge_port_group

/* The multicast port information structure that joins a multicast group * *

struct Net_bridge_port_group {

Structnet_bridge_port *port;//joins the multicast group's bridge port

Structnet_bridge_port_group *next;//The next multicast group detailed parameter structure (multiple ports can be joined to the same multicast group)

Structhlist_node mglist;

Structrcu_head RCU;//RCU Table Head

Structtimer_list timer;//Multicast port expiration timer, if timed out, the multicast port is removed from the multicast port list of the multicast group database entry

Structtimer_list query_timer;//Query Timer

__BE32 addr;//Multicast group address, each multicast port also need a multicast group reason is, through this value can quickly find its associated multicast group database entries

U32 queries_sent;//the number of times a query package has been sent

};

Where the port list is used to add all the corresponding bridges to the addr of the multicast group

Next points to the next multicast port, and the next multicast group address is addr, only the port value is different.

Where mglist is used to add the multicast port to the Mglist linked list of port, through the mglist linked list of the bridge port, can find all the multicast groups that the bridge port joins.

The following is the relationship between these 3 data structures

Second, the initialization of igmpsnooping

The initialization of IGMP snooping is implemented using function Br_multicast_init, in which the primary multicast group forwards the maximum value of the hash array of the database table, sets the interval between sending the query message and the number of times the query message is sent, And initializes the bridge's IGMP query timer.

void Br_multicast_init (struct NET_BRIDGE*BR)

{

Br->hash_elasticity= 4;//The number of ports that can be associated in each multicast group IP

br->hash_max= 512; The maximum value of a hash array in an MDB

Br->multicast_router= 1;

Br->multicast_last_member_count= 2;

Br->multicast_startup_query_count= 2;

Br->multicast_last_member_interval= HZ;

br->multicast_query_response_interval= * HZ; Multicast query Maximum response time

br->multicast_startup_query_interval= * HZ/4; Open the interval between sending a query message

br->multicast_query_interval= * HZ; Query packet Send time interval

br->multicast_querier_interval= 255 * HZ;

br->multicast_membership_interval= * HZ;

Spin_lock_init (&br->multicast_lock);

Setup_timer (&br->multicast_router_timer,

br_multicast_local_router_expired, 0);

Setup_timer (&br->multicast_querier_timer,

br_multicast_local_router_expired, 0);

Setup_timer (&br->multicast_query_timer,br_multicast_query_expired,

(unsigned long) BR);

}

2, bridge and bridge port of the query timer

The query timer for bridge and bridge ports is mainly used to implement the continuous updating of IGMP snooping multicast database forwarding.

A) the BR Bridge query timer

For timer Br->multicast_query_timer, after opening the IGMP snooping function will open the bridge Port multicast query function, mainly divided into the following:

i) when the BR device is up and the IGMP snooping is turned on, the function br_multicast_open is invoked to open an immediate timeout query timer

II When IGMP snooping is restarted, function Br_multicast_open is also invoked to open an immediate timeout query timer.

/*

Turn on the igmpsnooping function of a bridge

1. Reset Send query Packet count

2, modify the bridge query timer

*/

void Br_multicast_open (struct NET_BRIDGE*BR)

{

Br->multicast_startup_queries_sent= 0;

if (br->multicast_disabled)

Return

Mod_timer (&br->multicast_query_timer,jiffies);

}

When the query timer for the bridge is timed out, the function br_multicast_query_expired is called to process, and for the bridge device, the function sends a multicast generic query packet to the upper layer for processing, if the upper protocol stack opens the IGMP proxy function, Will trigger the upper layer protocol stack to the LAN side of the device Universal Multicast query function. For the upper layer open IGMP proxy function, the query timer through the bridge to the LAN side device for the cycle of universal query, and then can indirectly implement IGMP snooping multicast forwarding database updates.

For the bridge query timer, because it requires the upper layer to open IGMP proxy function, and when the upper layer open IGMP proxy function, if the IGMP snooping function, you can send a common multicast query message to achieve a fast set up multicast group database to publish.

From the above program can be seen, it is dependent on whether to open IGMP proxy, rather than directly send a universal multicast group query message, this also satisfies the requirements of the IGMP protocol, that is, only multicast group routers to send multicast query messages.

B) query timer for bridge port

If the upper stack does not support the Igmpproxy function, the upper layer protocol stack will discard the common query message, it will not trigger the upper layer protocol stack on the LAN side devices of the universal query, there is no way to update the IGMP snooping multicast group forwarding database.

The code writer obviously also noticed this problem, so added the bridge Port Multicast query timer function, after the IGMP snooping function will open the bridge Port multicast query function, divided into the following two kinds of situations:

1, when a bridge port up and open IGMP snooping, through the indirect call __br_multicast_enable_port, start an immediate expiration of the bridge port query timer

2. When you reopen the IGMP snooping feature, start a query timer for the bridge port that expires immediately by calling __br_multicast_enable_port.

Here we analyze the function __br_multicast_enable_port.

Static Void__br_multicast_enable_port (struct Net_bridge_port *port)

{

Port->multicast_startup_queries_sent= 0;

if (Try_to_del_timer_sync (&port->multicast_query_timer) >= 0 | |

Del_timer (&port->multicast_query_timer))

Mod_timer (&port->multicast_query_timer,jiffies);

}

The function is also relatively simple, mainly to open an immediate timeout of the bridge port timer, timeout will be performed after the timeout processing function br_multicast_port_query_expired.

Static voidbr_multicast_port_query_expired (unsigned Long data)

{

Structnet_bridge_port *port = (void *) data;

Structnet_bridge *BR = port->br;

Spin_lock (&br->multicast_lock);

if (port->state = = Br_state_disabled | |

Port->state = = br_state_blocking)

Gotoout;

if (Port->multicast_startup_queries_sent <

Br->multicast_startup_query_count)

port->multicast_startup_queries_sent++;

Br_multicast_send_query (Port->br,port,

Port->multicast_startup_queries_sent);

Out

Spin_unlock (&br->multicast_lock);

}

The structure of the function is relatively simple, mainly to determine whether the bridge port is in forward state, and then call the function Br_multicast_send_query send a general query message.

For function br_multicast_send_query, it can send multicast group query message to local upper layer protocol stack, and send the multicast group General query message from the specified bridge port.

Let's analyze the function br_multicast_send_query

/*

1. Call function Br_multicast_alloc_query construct a universal multicast Group query message

2. When the bridge port is not empty, send the query message from the corresponding port

3, for the bridge port is empty, the query message sent to the upper layer protocol stack

4, update the bridge or bridge port of the query timer.

*/

static void Br_multicast_send_query (Structnet_bridge *br,

struct Net_bridge_port *port, U32 sent)

{

Unsignedlong time;

Structsk_buff *SKB;

if (!netif_running (br->dev) | | | br->multicast_disabled | |

Timer_pending (&br->multicast_querier_timer))

Return

/* Construct a generic query packet * *

skb= br_multicast_alloc_query (BR, 0);

if (!SKB)

Gototimer;

if (port) {

__skb_push (skb,sizeof (struct ETHHDR));

skb->dev= port->dev;

Nf_hook (Pf_bridge,nf_br_local_out, SKB, NULL, Skb->dev,

Dev_queue_xmit);

}else

Netif_rx (SKB);

Timer

Time= jiffies;

Time+= sent < Br->multicast_startup_query_count?

Br->multicast_startup_query_interval:

br->multicast_query_interval;

Mod_timer (Port &port->multicast_query_timer:

&br->multicast_query_timer, time);

}

The above is the bridge and bridge Port multicast query timer working principle.

Iii. opening and closing of igmpsnooping

The opening and closing of IGMP snooping is realized by function Br_multicast_toggle

For the opening and closing of IGMP snooping, the igmpsnooping is now enabled and closed through SYSFS.

We can enable or disable IGMP via brctl by adding the IOCTL interface snooping

/*

Function: Turn on or off the igmpsnooping function.

Modifications are allowed only if the value to be set is different from the current value of br->multicast_disabled.

When the igmpsnooping feature is turned on, recreate the multicast group forwarding database table and call the multicast query timer of the Br_multicast_open and the __br_multicast_enable_port startup bridge and the bridge port.

*/

int Br_multicast_toggle (struct net_bridge*br, unsigned long val)

{

Structnet_bridge_port *port;

Interr =-enoent;

Spin_lock (&br->multicast_lock);

if (!netif_running (Br->dev))

Gotounlock;

Err= 0;

/* If the value you want to set is the same as the current value, return directly.

if (br->multicast_disabled = =!val)

Gotounlock;

Br->multicast_disabled=!val;

* * When IGMP snooping is off, there is no release br->mdb*/

if (br->multicast_disabled)

Gotounlock;

/*

1, when you open IGMP snooping, if br->mdb, Br->mdb->old are not 0,

Indicates a problem with the Br->mdb value, the IGMP snooping feature is turned off

2, when the IGMP snooping open, if the Br->mdb is not 0, and Br->mdb->old is 0,

Then the Br_mdb_rehash is invoked to recalculate the hash value for the multicast group items in the original Br->mdb

and stored in the new Br->mdb, release the space occupied by the original Br->mdb * *

if (Br->mdb) {

if (br->mdb->old) {

Err=-eexist;

Rollback

Br->multicast_disabled=!! Val

Gotounlock;

}

Err= Br_mdb_rehash (&br->mdb, Br->mdb->max,

br->hash_elasticity);

if (ERR)

Gotorollback;

}

/*

1, reset BR send the query packet statistics count

2, modify the BR of the multicast query timer Multicast_query_timer value

*/

Br_multicast_open (BR);

/*

For each port on the BR bridge group

1, reset port to send query packet statistics count

2, delete the port of the query timer, and rescheduling

*/

List_for_each_entry (port,&br->port_list, list) {

if (port->state = = Br_state_disabled | |

Port->state = = br_state_blocking)

Continue

__br_multicast_enable_port (port);

}

Unlock

Spin_unlock (&br->multicast_lock);

Returnerr;

}

This completes the igmpsnooping data structure and initialization of the introduction, the following section analysis of IGMP snooping receive processing functions.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.