0

I have an interface that is in link up.

If I try the following code (that sends out an IPv6 multicast ICMP packet), I get EADDRNOTAVAIL after a few times. To fix the problem I give a ifconfig down/up to the interface but after a few times I get again the problem.

#!/usr/bin/env python3

import socket, time, logging
from socket import AF_INET6, AF_INET

while True:
    
    bArray = b'\x80\0\0\0\0\0\0\0'

    send_socket = socket.socket(socket.AF_INET6, socket.SOCK_RAW, socket.getprotobyname('ipv6-icmp'))
    send_socket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_UNICAST_HOPS, 1)
    send_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    send_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
    send_socket.setsockopt(socket.SOL_SOCKET, socket.SO_BINDTODEVICE, str('ens26f1' + '\0').encode('utf-8'))

    logging.debug("Multicast ping from " + 'ens26f1')
    print("Multicast ping from " + 'ens26f1')
    
    send_socket.sendto(bArray,('ff02::1',0))
    send_socket.close()
    
    time.sleep(2)

Using strace I see that all system calls for the socket are successful apart from the sendto that when works is:

sendto(23, "\200\0\0\0\0\0\0\0", 8, 0, {sa_family=AF_INET6, sin6_port=htons(0), sin6_flowinfo=htonl(0), inet_pton(AF_INET6, "ff02::1", &sin6_addr), sin6_scope_id=0}, 28) = 8

while when getting the error is:

sendto(23, "\200\0\0\0\0\0\0\0", 8, 0, {sa_family=AF_INET6, sin6_port=htons(0), sin6_flowinfo=htonl(0), inet_pton(AF_INET6, "ff02::1", &sin6_addr), sin6_scope_id=0}, 28) = -1 EADDRNOTAVAIL (Cannot assign requested address)

The problem happens in Rocky Linux 9.1 and also the command:

ping6 -I ens6f0 ff02::1

I get this strace log with EADDRNOTAVAIL error.

sendmsg(3, {msg_name={sa_family=AF_INET6, sin6_port=htons(58), sin6_flowinfo=htonl(0), inet_pton(AF_INET6, "ff02::1", &sin6_addr), sin6_scope_id=0}, msg_namelen=28, msg_iov=[{iov_base="\200\0\0\0\0\0\0\v\335\265\370c\0\0\0\0\223\17\7\0\0\0\0\0\20\21\22\23\24\25\26\27"..., iov_len=64}], msg_iovlen=1, msg_control=[{cmsg_len=36, cmsg_level=SOL_IPV6, cmsg_type=0x32}], msg_controllen=40, msg_flags=0}, 0) = -1 EADDRNOTAVAIL (Cannot assign requested address)

It happens on Rocky Linux 9.1, not seen in Ubuntu 20.04.

James Risner
  • 5,451
  • 11
  • 25
  • 47

0 Answers0