[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

(usagi-users 04076) IPV6_PREFER_SRC_COA: connect returns EINVAL



Hi,

I'm trying to get an app to communicate from the CoA.  Works flawless if I 
bind the socket explicitly, but the newly added support for RFC5014 does not 
seem to work.

What I do:

  uint32_t prefs = IPV6_PREFER_SRC_COA;
  socklen_t optlen = sizeof(prefs);
  if (setsockopt(sfd, IPPROTO_IPV6, IPV6_ADDR_PREFERENCES, (void *)&prefs,
      optlen) == -1)
          err(1, "setsockopt");
  if (getsockopt(sfd, IPPROTO_IPV6, IPV6_ADDR_PREFERENCES, (void *)&prefs, 
      &optlen) == -1)
          err(1, "getsocktopt");

  printf("0x%0x\n", prefs);

  struct sockaddr_in6 sin6 = {0};
  socklen_t slen = sizeof(sin6); 
  sin6.sin6_family = AF_INET6;   
  sin6.sin6_port = htons(4);  
  inet_pton(AF_INET6, argv[2], &sin6.sin6_addr);
  if (connect(sfd, (struct sockaddr *)&sin6, sizeof(sin6)) == -1)
          err(1, "connect");
  if (getsockname(sfd, (struct sockaddr *)&sin6, &slen) == -1)
          err(1, "getsockname");

  char ipstr[46];
  inet_ntop(AF_INET6, &sin6.sin6_addr, ipstr, 46);
  printf("%s\n", ipstr);

The setsockopt succeeds and returns 0x104 (IPV6_PREFER_SRC_COA | 
IPV6_PREFER_SRC_PUBTMP_DEFAULT).  The connect fails, however, with EINVAL.  
Setting IPV_PREFER_SRC_HOME or leaving IPV6_ADDR_PREFERENCES alone works and 
sets the HoA as source.

"ip addr show" output is attached.

I can't figure out where the EINVAL is coming from.  I was expecting 
EADDRNOTAVAIL from ipv6_dev_get_saddr(), but EINVAL is a bit unspecific. Any 
ideas where to look?

-- 
/"\  Best regards,                      | mlaier@xxxxxxxxxxx
\ /  Max Laier                          | ICQ #67774661
 X   http://pf4freebsd.love2party.net/  | mlaier@EFnet
/ \  ASCII Ribbon Campaign              | Against HTML Mail and News
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ip6tnl0: <NOARP> mtu 1460 qdisc noop state DOWN 
    link/tunnel6 :: brd ::
3: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000
    link/ether 00:50:56:ad:4f:73 brd ff:ff:ff:ff:ff:ff
    inet 192.168.4.119/24 brd 192.168.4.255 scope global eth0
    inet6 fe80::250:56ff:fead:4f73/64 scope link 
       valid_lft forever preferred_lft forever
4: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000
    link/ether 00:50:56:ad:6a:b5 brd ff:ff:ff:ff:ff:ff
    inet6 fdfd:b6f0:1fd4:6001:250:56ff:fead:6ab5/64 scope global dynamic 
       valid_lft 2592000sec preferred_lft 604800sec
    inet6 fe80::250:56ff:fead:6ab5/64 scope link 
       valid_lft forever preferred_lft forever
5: eth2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
    link/ether 00:50:56:ad:42:00 brd ff:ff:ff:ff:ff:ff
6: eth3: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
    link/ether 00:0c:29:38:61:78 brd ff:ff:ff:ff:ff:ff
8: ip6tnl1@eth1: <POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1460 qdisc noqueue state UNKNOWN 
    link/tunnel6 fdfd:b6f0:1fd4:6001:250:56ff:fead:6ab5 peer fdfd:b6f0:1fd4:2001::1
    inet6 fdfd:b6f0:1fd4:2001::2/128 scope global home nodad dynamic 
       valid_lft 2587686sec preferred_lft 600486sec
    inet6 fe80::250:56ff:fead:6ab5/64 scope link 
       valid_lft forever preferred_lft forever