Hello list, more insights since my last post. Here is a small code to trigger the bug (end of email). When you run it on 9.0-RC1, it gets an alias address instead of the main inet address: % ./get-ip re0 inet: 192.168.2.10 # Main address being 192.168.1.148 On 8.2-RELEASE, all goes well: % ./get-ip re0 inet: PUBLIC_IP4 Is something broken, or a behaviour has changed since 8.2-RELEASE? Best regards, --8<-- #include <sys/types.h> #include <sys/socket.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <net/if.h> #include <sys/sockio.h> #include <string.h> #include <netinet/in.h> #include <arpa/inet.h> int main(int argc, char *argv[]) { int fd; struct ifreq ifr; const struct sockaddr_in *sa; fd = socket(AF_INET, SOCK_DGRAM, 0); if (fd < 0) { perror("socket"); exit(-1); } memset(&ifr, 0, sizeof(struct ifreq)); strlcpy(ifr.ifr_name, argv[1], sizeof(ifr.ifr_name)); if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) { sa = (const struct sockaddr_in *) &ifr.ifr_addr; printf("inet: %s\n", inet_ntoa(sa->sin_addr)); } else { perror("ioctl"); exit(-1); } exit(0); } --8<-- -- ^ ___ ___ http://www.GomoR.org/ <-+ | / __ |__/ Senior Security Engineer | | \__/ | \ ---[ zsh$ alias psed='perl -pe ' ]--- | +--> Net::Frame <=> http://search.cpan.org/~gomor/ <---+
On 2011-11-15 18:10:01 (+0100), GR <freebsd@gomor.org> wrote:> more insights since my last post. Here is a small code to trigger the bug (end of email). > When you run it on 9.0-RC1, it gets an alias address instead of the main inet address: > > % ./get-ip re0 > inet: 192.168.2.10 > # Main address being 192.168.1.148 > > On 8.2-RELEASE, all goes well: > % ./get-ip re0 > inet: PUBLIC_IP4 > > Is something broken, or a behaviour has changed since 8.2-RELEASE? >I think the relevant bit of the code is found in sys/netinet/in.c. If your ioctl doesn't specify an IP address we end up in this bit: TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { iap = ifatoia(ifa); if (iap->ia_addr.sin_family == AF_INET) { if (td != NULL && prison_check_ip4(td->td_ucred, &iap->ia_addr.sin_addr) != 0) continue; ia = iap; break; } } The 'ia' pointer is later used to return the IP address. In other words: it returns the first address on the interface of type IF_INET (which isn't assigned to a jail). I think the order of the addresses is not fixed, or rather it depends on the order in which you assign addresses. In the handling of SIOCSIFADDR new addresses are just appended: TAILQ_INSERT_TAIL(&ifp->if_addrhead, ifa, ifa_link); I don't believe this has changed since 8.0. Is it possible something changed in the network initialisation, leading to the addresses being assigned in a different order? Eagerly awaiting to be told I'm wrong, Kristof
On (15/11/2011 18:10), GR wrote:> Hello list, > > more insights since my last post. Here is a small code to trigger the bug (end of email). > When you run it on 9.0-RC1, it gets an alias address instead of the main inet address: > > % ./get-ip re0 > inet: 192.168.2.10 > # Main address being 192.168.1.148 > > On 8.2-RELEASE, all goes well: > % ./get-ip re0 > inet: PUBLIC_IP4 > > Is something broken, or a behaviour has changed since 8.2-RELEASE?Your test case looks ok and works as expexted for me on 10-CURRENT, both without aliases and after adding alias to interface. Perhaps it's the way you add aliases (libdnet ?). I've used: ifconfing em0 alias OTHERIP Thanks, Gleb.> > Best regards, > > > --8<-- > #include <sys/types.h> > #include <sys/socket.h> > #include <stdio.h> > #include <stdlib.h> > #include <unistd.h> > #include <net/if.h> > #include <sys/sockio.h> > #include <string.h> > #include <netinet/in.h> > #include <arpa/inet.h> > > int > main(int argc, char *argv[]) > { > int fd; > struct ifreq ifr; > const struct sockaddr_in *sa; > > fd = socket(AF_INET, SOCK_DGRAM, 0); > if (fd < 0) { > perror("socket"); > exit(-1); > } > > memset(&ifr, 0, sizeof(struct ifreq)); > strlcpy(ifr.ifr_name, argv[1], sizeof(ifr.ifr_name)); > > if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) { > sa = (const struct sockaddr_in *) &ifr.ifr_addr; > printf("inet: %s\n", inet_ntoa(sa->sin_addr)); > } > else { > perror("ioctl"); > exit(-1); > } > > exit(0); > } > --8<-- > > -- > ^ ___ ___ http://www.GomoR.org/ <-+ > | / __ |__/ Senior Security Engineer | > | \__/ | \ ---[ zsh$ alias psed='perl -pe ' ]--- | > +--> Net::Frame <=> http://search.cpan.org/~gomor/ <---+ > > _______________________________________________ > freebsd-current@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-current > To unsubscribe, send any mail to "freebsd-current-unsubscribe@freebsd.org"