Subject: Re: bonding xmit_policy

From: Nicolas de Pesloüan<[email-masked]>
Date: Sun, 13 Nov 2011 21:26:50 +0100

Le 13/11/2011 03:55, Simon Chen a écrit :
> Hi folks,
>
> It looks like that there are three entries in xmit_policy (hashing for
> deciding egress phy int) for bonded interfaces:
>
> const struct bond_parm_tbl xmit_hashtype_tbl[] = {
> {       "layer2",               BOND_XMIT_POLICY_LAYER2},
> {       "layer3+4",             BOND_XMIT_POLICY_LAYER34},
> {       "layer2+3",             BOND_XMIT_POLICY_LAYER23},
> {       NULL,                   -1},
> };
>
>
> We can set the xmit_policy either at module initiation, or later via
> /sys. However, this xmit_policy isn't really read anywhere. Are
> different policies really implemented?

The table is used in two different locations:

In drivers/net/bonding/bond_main.c:

	xmit_hashtype = bond_parse_parm(xmit_hash_policy, xmit_hashtype_tbl);
	[...]
	params->xmit_policy = xmit_hashtype;

In drivers/net/bonding/bond_sysfs.c:

	new_value = bond_parse_parm(buf, xmit_hashtype_tbl);
	[...]
	bonds->params.xmit_policy = new_value;

Then, in drivers/net/bonding/bond_main.c, the value in bonds->params.xmit_policy is used to setup a 
callback into bond->xmit_hash_policy.

	static void bond_set_xmit_hash_policy(struct bonding *bond)
	{
	        switch (bond->params.xmit_policy) {
	        case BOND_XMIT_POLICY_LAYER23:
	                bond->xmit_hash_policy = bond_xmit_hash_policy_l23;
	                break;
	        case BOND_XMIT_POLICY_LAYER34:
	                bond->xmit_hash_policy = bond_xmit_hash_policy_l34;
	                break;
	        case BOND_XMIT_POLICY_LAYER2:
         	default:
	                bond->xmit_hash_policy = bond_xmit_hash_policy_l2;
	                break;
	        }
	}

Then, in drivers/net/bonding/bond_3ad.c and in drivers/net/bonding/bond_main.c, the callback is used 
to select a slave for xmit, for the two modes where xmit_hash_policy have a meaning:

         slave_agg_no = bond->xmit_hash_policy(skb, slaves_in_agg);

         slave_no = bond->xmit_hash_policy(skb, bond->slave_cnt);

So, yes, those policies are really implemented.

	Nicolas.