On Sat, Jun 24, 2017 at 04:48:29PM +0800, Hangbin Liu wrote:
>       struct {
>               struct nlmsghdr hdr;
> -             struct rtgenmsg gen;
> +             struct ifinfomsg ifm;
>       } __attribute__((packed)) request;
>
>       memset(&sa, 0, sizeof(sa));
>       sa.nl_family = AF_NETLINK;
>
>       memset(&request, 0, sizeof(request));
> -     request.hdr.nlmsg_len = NLMSG_LENGTH(sizeof(request.gen));
> +     request.hdr.nlmsg_len = NLMSG_LENGTH(sizeof(request.ifm));
>       request.hdr.nlmsg_type = RTM_GETLINK;
> -     request.hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP;
> +     request.hdr.nlmsg_flags = NLM_F_REQUEST;
>       request.hdr.nlmsg_seq = 1;
>       request.hdr.nlmsg_pid = 0;
> -     request.gen.rtgen_family = AF_UNSPEC;
> +     request.ifm.ifi_family = AF_UNSPEC;
> +     request.ifm.ifi_index = if_index;
> +     request.ifm.ifi_change = 0xffffffff;

What about portability on older kernel versions?  We need to run on
kernels starting with v3.0.  The rtnetlink(7) man page says:

    struct ifinfomsg {
        unsigned char  ifi_family; /* AF_UNSPEC */
        unsigned short ifi_type;   /* Device type */
        int            ifi_index;  /* Interface index */
        unsigned int   ifi_flags;  /* Device flags  */
        unsigned int   ifi_change; /* change mask */
    };

    ifi_flags contains the device flags, see netdevice(7); ifi_index
    is  the  unique interface index (since Linux 3.7, it is possible
    to feed a nonzero value with the RTM_NEWLINK message, thus  cre‐
    ating a link with the given ifindex); ifi_change is reserved for
    future use and should be always set to 0xFFFFFFFF.

If we could always use a per-port rtnl socket, this would be an
improvement.  Back when I introduced rtnl, I wrote this:

    From 0b3c045a4236f128ab4c1592e6cc91adc1cd6eb0 Mon Sep 17 00:00:00 2001
    From: Richard Cochran <richardcoch...@gmail.com>
    Date: Sun, 31 Jul 2016 12:08:24 +0200
    Subject: rtnl: Introduce RT netlink sockets.

    This patch adds a source module that implements RT netlink sockets
    for the purpose of link monitoring.  Unfortunately the netlink API
    offers no possibility for per-port notification.  Instead it
    forces us to use a de-multiplexing pattern.

At that time, I added one extra FD into clock->pollfdp[], and the
clock then farms out the information to the ports.  I really did not
to do it that way.  A better way would have been to add a new per-port
FD into fd.h, something like this:

    enum {
            FD_EVENT,
            FD_GENERAL,
            FD_ANNOUNCE_TIMER,
            FD_SYNC_RX_TIMER,
            FD_DELAY_TIMER,
            FD_QUALIFICATION_TIMER,
            FD_MANNO_TIMER,
            FD_SYNC_TX_TIMER,
/*here*/    FD_RTNL,
            N_POLLFD,
    };

    struct fdarray {
            int fd[N_POLLFD];
    };

This would simply your patch set, wouldn't it?

Thanks,
Richard

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to