[PATCH 2/4] Add new rtnl_link_af_data_compare function to compare af_data

Roopa Prabhu roopa at cumulusnetworks.com
Mon Jan 14 19:35:13 EST 2013


On 1/14/13 8:01 AM, Roopa Prabhu wrote:
> On 1/14/13 12:02 AM, Thomas Graf wrote:
>> On 01/13/13 at 03:09pm, Roopa Prabhu wrote:
>>> The reason i did not add this check because this api could be used
>>> for comparing IFLA_AF_SPEC too. In which case the IFLA_AF_SPEC
>>> family might not be same as l_family.
>>>
>>> Right now link_compare only compares IFLA_PROTINFO. But it could be
>>> extended to compare af_data belonging to IFLA_AF_SPEC as well.
>>>
>>> Let me know what you think.
>>
>> OK, makes sense.
>>
>> Please make the API more solid then and document the exact meaning
>> of the family parameter. As of now, an invalid family value will
>> be used blindly to index the ops array. Checking the return value
>> of rtnl_link_af_ops_lookup() would be enough already as it
>> enforces> 0&& < AF_MAX.
>>
> ok thanks. Will do. I will re-spin the series.
>

Thomas, Just thought i should go over the api details with you before i 
re-spin.

Below is the new api. But, I have not exposed the attributes under 
documentation and was not thinking of exposing it.

In which case I am now thinking of not making this particular api 
public. And if needed maybe expose a simpler wrapper api in the future.

eg simple public api. returns 0 or 1.
int rtnl_link_af_data_compare(struct rtnl_link *a, struct rtnl_link *b,
                               int family)


make the below api local to link.c and rename it to af_data_compare

pls let me know what you think.

thanks.


/**
  * Compare af data of a specific link address family
  * @arg a               Link object a
  * @arg b               Link object b
  * @arg family          af data address family
  * @arg attrs           attribute mask supported by af data
  * @arg flags           compare flags
  *
  * This function will compare af_data of two links
  * a and b of family given by arg family
  *
  * @return 0 on compare success or > 0 on compare failure
  */
int rtnl_link_af_data_compare(struct rtnl_link *a, struct rtnl_link *b,
                               int family, uint32_t attrs, int flags)
{
         struct rtnl_link_af_ops *af_ops = rtnl_link_af_ops_lookup(family);

         if (!af_ops)
                 return 1;

         if (!a->l_af_data[family] && !b->l_af_data[family])
                 return 0;

         if (!a->l_af_data[family] || !b->l_af_data[family])
                 return ~0;

         if (af_ops->ao_compare)
                 return af_ops->ao_compare(a, b, family, attrs, flags);

         return 0;
}



More information about the libnl mailing list