Bug 265489 - IPV6 Non-Local Bind Operation timeout.
Summary: IPV6 Non-Local Bind Operation timeout.
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: Unspecified
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-net (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-07-29 00:23 UTC by todenerey
Modified: 2022-08-04 05:15 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description todenerey 2022-07-29 00:23:24 UTC
Hello, I creating socket() with IPV6_BINDANY option. I binding non-local ip address.

When running my test socket program getting error: "connect() failed. Operation timed out. errno: 60"

In Linux i using IP_FREEBIND and adding loopback address subnet good working. But 
in FreeBSD getting timed out error. 


In this case need rtadvd or firewalls configure? (no services is active)


setsockopt(sock, IPPROTO_IPV6, IPV6_BINDANY, &on, sizeof on);
Comment 1 Zhenlei Huang freebsd_committer freebsd_triage 2022-08-01 02:15:31 UTC
(In reply to todenerey from comment #0)
Can you please share a minimal program to demonstrate?
Comment 2 todenerey 2022-08-03 02:49:50 UTC
(In reply to Zhenlei Huang from comment #1)
#include <stdio.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <netinet/in.h>
#include <sys/socket.h>

const char *bind_ip = " "; // My /64 block ip.

const char *HOST = "2a01:4f8:c0c:bd0a::1";
const int PORT = 80;

int main()
{
    int sockfd;
    struct sockaddr_in6 sin;
    struct sockaddr_in6 sa;

    sockfd = socket(AF_INET6, SOCK_STREAM, 0);
    
    if(sockfd == -1) {
        perror("Socket error: ");

        return 1;
    }
    
    int on = 1;

    setsockopt(sockfd, IPPROTO_IPV6, IPV6_BINDANY, &on, sizeof(on));

    sin.sin6_family = AF_INET6;
    sin.sin6_port = htons(0);

    if(inet_pton(AF_INET6, bind_ip, &sin.sin6_addr) != 1)
    {
	fprintf(stderr, "Invalid bind source address.\n");

        return 1;
    }

	sa.sin6_family = AF_INET6;
    sa.sin6_port = htons(PORT);

    if(inet_pton(AF_INET6, HOST, &sa.sin6_addr) != 1)
    {
	fprintf(stderr, "Invalid host address.\n");

        return 1;
    }

    if(bind(sockfd, (struct sockaddr *) &sin, sizeof(sin)) == -1)
    {
        perror("Bind error: ");

        return 1;
    }


    if(connect(sockfd, (struct sockaddr *)&sa, sizeof(sa)) != 0) {
    	perror("Connect error: ");

        return 1;
    }


    printf("Connection successful!\n");

    close(sockfd);

    return 0;
}