0

I tried to plumb an IP address on an IPMP interface using the below sample code, the interface gets plumbed correctly (correct output in ifconfig -a). But running just the "ipadm" command does not show the plumbed interface and the running "ipadm show-addr" shows a '/?' in the description.

Seeing this behaviour on Solaris 11.1 and Solaris 11.2

#ipadm show-addr

ADDROBJ TYPE STATE ADDR

lo0/v4 static ok 127.0.0.1/8

ipmp0/? static ok X.X.X.X

lo0/v6 static ok ::1/128

// Code

int main(){

    int sd;
    //struct sockaddr *addr;
    struct sockaddr_in *addr;
    struct lifreq lifr;
    const char *aliasName;

    memset(&lifr, 0, sizeof(lifr));
    const char* networkInterfaceName = "ipmp0";
    // Here the actual address is written. Hiding here :)
    const char *inetAddress = "10.XX.XX.XX";
    const char *netmaskAddress = "255.255.252.0";

    strncpy(lifr.lifr_name, networkInterfaceName, sizeof(lifr.lifr_name));

    // Create socket
    if((sd = socket(AF_INET, SOCK_DGRAM, 0)) < 0){
       cout << "Error Socket Creation" << endl ;
    }

    // Add interface name
    if(ioctl(sd, SIOCLIFADDIF, &lifr) < 0){
       perror ("SIOCLIFADDIF");
       cout << "Error ioctl SIOCLIFADDIF" << endl ;
    }

    // Defines the netmask
    addr = (struct sockaddr_in*) &(lifr.lifr_addr);
    addr->sin_family = AF_INET;
    addr->sin_addr.s_addr = inet_addr(netmaskAddress);

    if(ioctl(sd, SIOCSLIFNETMASK, &lifr) < 0){
       perror("SIOCSLIFNETMASK");
       cout << "Error ioctl SIOCSLIFNETMASK" << endl;
    }

    // Set up the new interface
    // Defines the address of the new interface.
    addr->sin_addr.s_addr = inet_addr(inetAddress);
    if(ioctl(sd, SIOCSLIFADDR, &lifr) < 0){
       perror ("SIOCLIFADDR");
       cout << "Error ioctl SIOCLIFADDR" << endl ;
    }
    if(ioctl(sd, SIOCGLIFFLAGS, &lifr)< 0){
       perror("SIOCGLIFFLAGS");
       cout << "Error ioctl SIOCGLIFFLAGS" << endl;
    }
    lifr.lifr_flags |= IFF_UP;
    if(ioctl(sd, SIOCSLIFFLAGS, &lifr) < 0){
       perror("SIOCSLIFFLAGS");
       cout << "Error ioctl SIOCSLIFFLAGS" << endl;
    }
    close(sd);
    return 0;
}

What is the bug in my sample code?

atish shimpi
  • 4,873
  • 2
  • 32
  • 50
ktime
  • 63
  • 13
  • That is probably because you use old Solaris 10-like API with ioctls and `lifreq` structure. I presume that it was kept for backwards compability, but all new `ipadm`-related functions were implemented via `libipadm`. It seems that this field: http://src.illumos.org/source/xref/illumos-gate/usr/src/lib/libipadm/common/libipadm_impl.h#69 is an address object name (the one which is shown as `?`). – myaut Jan 29 '15 at 22:20
  • Ok. I do see a call being made to "/lib/libipadm.so.1" in the truss of "ifconfig command". So I assume this is for "updating the ipmgmtd daemon's aobjmap with the logical interface information." as indicated (https://github.com/joyent/illumos-joyent/blob/master/usr/src/lib/libipadm/common/ipadm_addr.c"). I wonder if ioctls aren't sufficient enough to get this done. Just using "ioctls" won't rectify the ipadm output (?) Also, there is difference in the behavior on Solaris 11.1 & 11.2. In 11.1 "ipadm" doesn't even show the plumbed interface, on 11.2 it shows the plumbed interface with a "/?". – ktime Jan 30 '15 at 15:32

1 Answers1

0

Take a look to this:

From: http://docs.oracle.com/cd/E26502_01/html/E28987/geyrf.html

"An address object that is listed as interface/? indicates that the address was configured on the interface by an application that did not use libipadm APIs. Such applications are not under the control of the ipadm command, which requires that the address object name use the format interface/user-defined-string. For examples of assigning IP addresses, see How to Configure an IP Interface."

Pab
  • 21
  • 4