[PATCH 13/13] idiag: add a oo_compare() function for idiag_msg objects

Cong Wang xiyou.wangcong at gmail.com
Tue Nov 25 13:57:50 PST 2014


On Mon, Nov 24, 2014 at 8:14 AM, Thomas Haller <thaller at redhat.com> wrote:
> Having a oo_keygen() function only makes sense together with a
> oo_compare() function because after hashing, you still have to compare
> the objects for equality (in case of hash collission).
>
[...]
> +static int idiagnl_compare(struct nl_object *_a, struct nl_object *_b,
> +                           uint32_t attrs, int flags)
> +{
> +       struct idiagnl_msg *a = (struct idiagnl_msg *) _a;
> +       struct idiagnl_msg *b = (struct idiagnl_msg *) _b;
> +       int diff = 0;
> +
> +#define _DIFF(ATTR, EXPR) ATTR_DIFF(attrs, IDIAGNL_ATTR_##ATTR, a, b, EXPR)
> +       diff |= _DIFF(FAMILY, a->idiag_family != b->idiag_family);
> +       diff |= _DIFF(STATE,  a->idiag_state != b->idiag_state);
> +       diff |= _DIFF(SPORT,  a->idiag_sport != b->idiag_sport);
> +       diff |= _DIFF(DPORT,  a->idiag_dport != b->idiag_dport);
> +#undef _DIFF
> +       return diff;
> +}
> +

You need to compare all the 4-tuple for a socket, that is, you missed
dst addr and src addr.



More information about the libnl mailing list