Netdev List
 help / color / mirror / Atom feed
From: "François-Xavier Le Bail" <fx.lebail@yahoo.com>
To: Eric Dumazet <eric.dumazet@gmail.com>
Cc: "netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: Re: [RFC] The Linux kernel IPv6 stack don't follow the RFC 4942 recommendation
Date: Thu, 10 Nov 2011 02:58:45 -0800 (PST)	[thread overview]
Message-ID: <1320922725.65072.YahooMailNeo@web126002.mail.ne1.yahoo.com> (raw)
In-Reply-To: <1320485406.16908.4.camel@edumazet-laptop>

----- Original Message -----

> From: Eric Dumazet <eric.dumazet@gmail.com>
> To: François-Xavier Le Bail <fx.lebail@yahoo.com>
> Cc: "netdev@vger.kernel.org" <netdev@vger.kernel.org>
> Sent: Saturday, November 5, 2011 10:30 AM
> Subject: Re: [RFC] The Linux kernel IPv6 stack don't follow the RFC 4942 recommendation
> 
> Le samedi 05 novembre 2011 à 01:39 -0700, François-Xavier Le Bail a
> écrit :
> 
>> 
>>  I will study and test these options for my application server
> 
> Here is a sample of use of the IPv4 part, an udpecho service that use
> IP_PKTINFO and IP_RECVTOS/IP_TOS to be able to use multihomed machine,
> and reflect TOS field as well.
> [. . .]

Hi,

I have updated the code for IPv6.

When a UDP client send to an unicast address on a multihomed Linux 3.0.0 host, from another host, it's OK.
For example :
setup 2001::1 on eth0, 2a01::1 on eth1.
send to 2001::1, recv from 2001::1.
send to 2a01::1, recv from 2a01::1.

When the UDP client send to an Subnet-Router anycast address on a multihomed Linux 3.0.0 host, from another host, it's KO.
send to 2001:: or 2a01::, the udpecho server display "sendmsg: Invalid argument".

Any idea ?

Thanks,
Francois-Xavier

Here is the server code:
----------------------------------------------------------------------
// Here is a sample of use of the IPv6 part, an udpecho service that use
// IPV6_RECVPKTINFO to be able to use multihomed machine.

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <linux/udp.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <arpa/inet.h>

#define PORT 4040

struct in6_pktinfo {
        struct in6_addr ipi6_addr;  /* src/dst IPv6 address */
    unsigned int ipi6_ifindex;  /* send/recv interface index */
};

int pktinfo_get(struct msghdr *my_hdr, struct in6_pktinfo *pktinfo)
{
    int res = -1;

    fprintf(stderr, "pktinfo_get()\n");
    if (my_hdr->msg_controllen > 0) {
        struct cmsghdr *get_cmsg;
        for (get_cmsg = CMSG_FIRSTHDR(my_hdr); get_cmsg;
            get_cmsg = CMSG_NXTHDR(my_hdr, get_cmsg)) {
            if (get_cmsg->cmsg_type == IPV6_PKTINFO) {
                struct in6_pktinfo *get_pktinfo = (struct in6_pktinfo *)CMSG_DATA(get_cmsg);
                memcpy(pktinfo, get_pktinfo, sizeof(*pktinfo));
                res = 0;
            }
        }
    }
    return res;
}

int main(int argc, char *argv[])
{
    int fd = socket(AF_INET6, SOCK_DGRAM, 0);
    struct sockaddr_in6 addr, rem_addr;
    int res, on = 1;
    struct msghdr msghdr;
    struct iovec vec[1];
    char cbuf[512];
    char frame[4096];
    struct in6_pktinfo pktinfo;
    int c, count = 1000000;

    while ((c = getopt(argc, argv, "c:")) != -1) {
        if (c == 'c') count = atoi(optarg);
        }
    memset(&addr, 0, sizeof(addr));
    addr.sin6_family = AF_INET6;
    addr.sin6_port = htons(PORT);
    if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
        perror("bind");
        return 1;
    }
    //setsockopt(fd, IPPROTO_IPV6, IPV6_PKTINFO, &on, sizeof(on));
    setsockopt(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, &on, sizeof(on));

    while (1) {

        memset(&msghdr, 0, sizeof(msghdr));
        msghdr.msg_control = cbuf;
        msghdr.msg_controllen = sizeof(cbuf);
        msghdr.msg_iov = vec;
        msghdr.msg_iovlen = 1;
        vec[0].iov_base = frame;
        vec[0].iov_len = sizeof(frame);
        msghdr.msg_name = &rem_addr;
        msghdr.msg_namelen = sizeof(rem_addr);
        res = recvmsg(fd, &msghdr, 0);
        if (res == -1)
            break;
        if (pktinfo_get(&msghdr, &pktinfo) == 0) {

            //printf("Got IPV6_PKTINFO dst addr=%s\n", inet_ntoa(pktinfo.ipi6_addr));
            }
        /* ok, just echo reply this frame.
        * Using sendmsg() will provide IPV6_PKTINFO back to kernel
        * to let it use the 'right' source address
        * (destination address of the incoming packet)
        */
        vec[0].iov_len = res;
        res = sendmsg(fd, &msghdr, 0);
        if (res == -1) {
            perror ("sendmsg");
            break;
        }
        if (--count == 0)
            break;
    }
    return 0;
}

----------------------------------------------------------------------

  reply	other threads:[~2011-11-10 10:58 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-04 14:46 [RFC] The Linux kernel IPv6 stack don't follow the RFC 4942 recommendation François-Xavier Le Bail
2011-11-04 16:24 ` Eric Dumazet
2011-11-05  8:39   ` François-Xavier Le Bail
2011-11-05  9:20     ` Eric Dumazet
2011-11-18 10:15       ` Bjørn Mork
2011-11-05  9:30     ` Eric Dumazet
2011-11-10 10:58       ` François-Xavier Le Bail [this message]
2011-11-10 11:27         ` Eric Dumazet
2011-11-10 12:54           ` François-Xavier Le Bail
2011-11-10 15:23             ` François-Xavier Le Bail
2011-11-10 13:25         ` How to get the port values Naveen B N (nbn)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1320922725.65072.YahooMailNeo@web126002.mail.ne1.yahoo.com \
    --to=fx.lebail@yahoo.com \
    --cc=eric.dumazet@gmail.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox