Does FreeBSD stack support multiple IP addresses?

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Does FreeBSD stack support multiple IP addresses?

Grant Edwards-6
Can one assign multiple IP addresses (on different subnets) to a
single interface when using the eCos FreeBSD network stack?

I know modern BSD and Linux stacks all support that, but does the eCos
implementation?

--
Grant Edwards               grant.b.edwards        Yow! If Robert Di Niro
                                  at               assassinates Walter Slezak,
                              gmail.com            will Jodie Foster marry
                                                   Bonzo??


--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

Reply | Threaded
Open this post in threaded view
|

Re: Does FreeBSD stack support multiple IP addresses?

Grant Edwards-6
On 2016-02-19, Grant Edwards <[hidden email]> wrote:

> Can one assign multiple IP addresses (on different subnets) to a
> single interface when using the eCos FreeBSD network stack?
>
> I know modern BSD and Linux stacks all support that, but does the eCos
> implementation?

Some poking through the source doe and subsequent experimentation has
answered my question in the affirmative.

You use SIOCAIFADDR(_IN6) instead of SIOCASIFADDR and its brethren.

--
Grant Edwards               grant.b.edwards        Yow! Today, THREE WINOS
                                  at               from DETROIT sold me a
                              gmail.com            framed photo of TAB HUNTER
                                                   before his MAKEOVER!


--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

Reply | Threaded
Open this post in threaded view
|

Re: Does FreeBSD stack support multiple IP addresses?

Lambrecht Jürgen
On 02/19/2016 07:11 PM, Grant Edwards wrote:

> On 2016-02-19, Grant Edwards <[hidden email]> wrote:
>
>> Can one assign multiple IP addresses (on different subnets) to a
>> single interface when using the eCos FreeBSD network stack?
>>
>> I know modern BSD and Linux stacks all support that, but does the eCos
>> implementation?
> Some poking through the source doe and subsequent experimentation has
> answered my question in the affirmative.
>
> You use SIOCAIFADDR(_IN6) instead of SIOCASIFADDR and its brethren.
>
I had 2 problems to assign 2 IP addresses with different netmasks:
- To assign an IP address an set a netmask are 2 different ioctl calls.
To set the netmask, you cannot specify for which IP address you set it.
The code (current/src/sys/netinet/in.c) is written in such a way that
the netmask is set on the last IP address you added on that interface.
So that should be OK if you keep the correct order.
- It is only possible to assign a class A/B/C netmask. CIDR netmasks are
not possible. I fixed current/src/sys/netinet/in.c for it, but I also
adapted the ioctl to combine setting IP address and netmask in 1 call
(so I cannot commit it back). Let me know if you want my fix.

Short answer: yes it is possible.

Kind regards,
Jürgen

P.S.: CIDR is possible in the freeBSD stack, it is only the ioctl in
current/src/sys/netinet/in.c that is the limitation

--
Jürgen Lambrecht
R&D Associate
Mobile: +32 499 644 531
Twitter: JGRLambrecht
Tel: +32 (0)51 303045    Fax: +32 (0)51 310670
http://www.televic-rail.com
https://www.facebook.com/TelevicRail
Televic Rail NV - Leo Bekaertlaan 1 - 8870 Izegem - Belgium
Company number 0825.539.581 - RPR Kortrijk

This electronic transmission is intended exclusively for the person or entity
to whom it is addressed and may contain confidential and/or privileged
material. Any disclosure, copying, distribution or other action based upon the
information by persons or entities other than the intended recipient is
prohibited. All e-mail correspondence from Televic Rail NV is only intended for
information purposes and can not result in contractual obligations. Commitments
under Televic Rail NV can only occur through regular exchange of letters,
signed by authorized persons in accordance with publication in the Belgian
Official Gazette.

--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

Reply | Threaded
Open this post in threaded view
|

Re: Does FreeBSD stack support multiple IP addresses?

Grant Edwards-6
On 2016-02-22, Lambrecht Jürgen <[hidden email]> wrote:
> On 02/19/2016 07:11 PM, Grant Edwards wrote:
>> On 2016-02-19, Grant Edwards <[hidden email]> wrote:
>>
>>> Can one assign multiple IP addresses (on different subnets) to a
>>> single interface when using the eCos FreeBSD network stack?
[...]

>> You use SIOCAIFADDR(_IN6) instead of SIOCASIFADDR and its brethren.
>
> I had 2 problems to assign 2 IP addresses with different netmasks:
>
> - To assign an IP address an set a netmask are 2 different ioctl
>   calls.  To set the netmask, you cannot specify for which IP
>   address you set it.  The code (current/src/sys/netinet/in.c) is
>   written in such a way that the netmask is set on the last IP
>   address you added on that interface.  So that should be OK if you
>   keep the correct order.

When I tried it, the SIOCAIFADDR ioctl() let me set both address and
netmask in a single call.  The "case SIOCAIFADDR" code falls through
into SIOCSIFNETMASK code.  That didn't work for you?

> - It is only possible to assign a class A/B/C netmask. CIDR netmasks are
>   not possible.

I think that's always been the case for this version of the stack,
hasn't it?

>   I fixed current/src/sys/netinet/in.c for it, but I also
>   adapted the ioctl to combine setting IP address and netmask in 1 call
>   (so I cannot commit it back). Let me know if you want my fix.

I'm confused: based on my experiments and examination of the source
code, it already works that way.

--
Grant Edwards               grant.b.edwards        Yow! Psychoanalysis??
                                  at               I thought this was a nude
                              gmail.com            rap session!!!


--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

Reply | Threaded
Open this post in threaded view
|

Re: Does FreeBSD stack support multiple IP addresses?

Lambrecht Jürgen
On 02/22/2016 04:05 PM, Grant Edwards wrote:

> On 2016-02-22, Lambrecht Jürgen <[hidden email]> wrote:
>> On 02/19/2016 07:11 PM, Grant Edwards wrote:
>>> On 2016-02-19, Grant Edwards <[hidden email]> wrote:
>>>
>>>> Can one assign multiple IP addresses (on different subnets) to a
>>>> single interface when using the eCos FreeBSD network stack?
> [...]
>>> You use SIOCAIFADDR(_IN6) instead of SIOCASIFADDR and its brethren.
>> I had 2 problems to assign 2 IP addresses with different netmasks:
>>
>> - To assign an IP address an set a netmask are 2 different ioctl
>>    calls.  To set the netmask, you cannot specify for which IP
>>    address you set it.  The code (current/src/sys/netinet/in.c) is
>>    written in such a way that the netmask is set on the last IP
>>    address you added on that interface.  So that should be OK if you
>>    keep the correct order.
> When I tried it, the SIOCAIFADDR ioctl() let me set both address and
> netmask in a single call.  The "case SIOCAIFADDR" code falls through
> into SIOCSIFNETMASK code.  That didn't work for you?
Indeed, I remember now that I saw that in the code, but then you have
the netmask according to the class A/B/C rules, and that is not what we
want.
>
>> - It is only possible to assign a class A/B/C netmask. CIDR netmasks are
>>    not possible.
> I think that's always been the case for this version of the stack,
> hasn't it?
Indeed.
>
>>    I fixed current/src/sys/netinet/in.c for it, but I also
>>    adapted the ioctl to combine setting IP address and netmask in 1 call
>>    (so I cannot commit it back). Let me know if you want my fix.
I changed a bit the use of the members of the "inet"-something struct
(in the ioctl call) to also use the netmask struct member that is
already in it. Because normally, when you call ioctl SIOCSIFNETMASK
separately, you specify the netmask in the same struct member where you
put the IP address for the SIOCAIFADDR call.
(I did a fast search in the linux code, but I am not used to that, so I
did not find the "Linux way")
> I'm confused: based on my experiments and examination of the source
> code, it already works that way.
>
Well, it is both.
Indeed, as you say above, "code falls through into SIOCSIFNETMASK code",
but then it sets "the netmask according to the class A/B/C rules", so
the netmask is _calculated_, not strictly _set_.
I am completely sure about this, I read that whole code part.
(And my collegues did the experimentation to set a 255.248.0.0 netmask
resulting in a 255.255.0.0 mask for 172.24.0.0 which is class B)

Kind regards,
Jürgen

--
Jürgen Lambrecht
R&D Associate
Mobile: +32 499 644 531
Twitter: JGRLambrecht
Tel: +32 (0)51 303045    Fax: +32 (0)51 310670
http://www.televic-rail.com
https://www.facebook.com/TelevicRail
Televic Rail NV - Leo Bekaertlaan 1 - 8870 Izegem - Belgium
Company number 0825.539.581 - RPR Kortrijk

This electronic transmission is intended exclusively for the person or entity
to whom it is addressed and may contain confidential and/or privileged
material. Any disclosure, copying, distribution or other action based upon the
information by persons or entities other than the intended recipient is
prohibited. All e-mail correspondence from Televic Rail NV is only intended for
information purposes and can not result in contractual obligations. Commitments
under Televic Rail NV can only occur through regular exchange of letters,
signed by authorized persons in accordance with publication in the Belgian
Official Gazette.
Reply | Threaded
Open this post in threaded view
|

Re: Does FreeBSD stack support multiple IP addresses?

Grant Edwards-6
On 2016-02-23, Lambrecht Jürgen <[hidden email]> wrote:
> On 02/22/2016 04:05 PM, Grant Edwards wrote:

>> When I tried it, the SIOCAIFADDR ioctl() let me set both address and
>> netmask in a single call.  The "case SIOCAIFADDR" code falls through
>> into SIOCSIFNETMASK code.  That didn't work for you?
>
> Indeed, I remember now that I saw that in the code, but then you have
> the netmask according to the class A/B/C rules, and that is not what we
> want.
>
>>> - It is only possible to assign a class A/B/C netmask. CIDR netmasks are
>>>    not possible.
>> I think that's always been the case for this version of the stack,
>> hasn't it?
> Indeed.

I just re-ran my tests and verified again that I'm able to set the IP
and netmask in a single call to ioctl(SIOCAIFADDR).  In my tests, I
tried:

 Address         Netmask
-----------      --------------
 11.0.0.104      255.0.0.0
 11.0.0.104      255.255.0.0
 11.0.0.104      255.255.255.0
 11.0.0.104      255.240.0.0
 11.0.0.104      240.0.0.0
 192.168.222.104 240.0.0.0
 192.168.222.104 255.0.0.0
 192.168.222.104 255.240.0.0
 192.168.222.104 255.255.0.0
 192.168.222.104 255.255.240.0
 192.168.222.104 255.255.255.0
 192.168.222.104 255.255.255.240

In all cases, subsequent calls to show_network_tables() showed the IP
address and netmask I requested in the ioctl() call and the correct
corresponding broadcast address.

I'm using an eCos snapshot from 2014.

>>>    I fixed current/src/sys/netinet/in.c for it, but I also adapted
>>>    the ioctl to combine setting IP address and netmask in 1 call
>>>    (so I cannot commit it back). Let me know if you want my fix.

The current SIOCAIFADDR code works fine for me.

> I changed a bit the use of the members of the "inet"-something
> struct (in the ioctl call) to also use the netmask struct member
> that is already in it. Because normally, when you call ioctl
> SIOCSIFNETMASK separately, you specify the netmask in the same
> struct member where you put the IP address for the SIOCAIFADDR call.

But the SIOCAIFADDR call as a _separate_ place where you put the
desired netmask, and AFIACT, that works.

> (I did a fast search in the linux code, but I am not used to that,
> so I did not find the "Linux way")
>
>> I'm confused: based on my experiments and examination of the source
>> code, it already works that way.
>>
> Well, it is both.  Indeed, as you say above, "code falls through
> into SIOCSIFNETMASK code",

> but then it sets "the netmask according to the class A/B/C rules",
> so the netmask is _calculated_, not strictly _set_.  I am completely
> sure about this, I read that whole code part.  (And my collegues did
> the experimentation to set a 255.248.0.0 netmask resulting in a
> 255.255.0.0 mask for 172.24.0.0 which is class B)

I don't know what to tell you other than "it works fine for
me". Unless the output from show_network_tables() is wrong...

--
Grant Edwards               grant.b.edwards        Yow! Give them RADAR-GUIDED
                                  at               SKEE-BALL LANES and
                              gmail.com            VELVEETA BURRITOS!!


--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

Reply | Threaded
Open this post in threaded view
|

Re: Does FreeBSD stack support multiple IP addresses?

Grant Edwards-6
On Wed, Feb 24, 2016 at 01:31:51PM +0100, Bob Brusa wrote:

> Hi,I am kind of misusing this email for the following reason:I sent
> a question to [hidden email] - and got it back as
> undeliverable. Then I sent a mail to their help desk and got it back
> as undeliverable. Third then, I sent a mail to
> [hidden email]. It came back as well.This
> triggers the question:
>
> Is the open source version of eCos dead?

I'd have to say pretty much yes.  There is very little development or
maintenance work being done on the open-source tree.  Browsing the CVS
repository via the web doesn't appear to work (the entire "net" tree
seems to have vanished), though I think checking out a copy via CVS on
the command line does still work.

I've been using eCos in one product line for 15 years, and that
product line is still being updated and still doing well.  We'll stick
with eCos as we continue to maintain/update those products.  But, I
wouldn't recommend the open-source version of eCos for a brand-new
product.  One area where several people have expressed concern is the
FreeBSD-based network stack.  It's based on a very old FreeBSD
snapshot and hasn't seen much in the way of updates since then.  I've
commited fixes for a few problems and to keep GCC happy, but AFAIK,
nobody has ever made any consistent effort to bring over fixes and
updates made by the "upstream" FreeBSD maintainers.

That said, I don't know anything about the commercial version from
eCos Centric and have no experience with it.

> Do you know something about this?

If you're asking about the mailing list problem you encountered, I
don't know anything about that...

--
Grant

--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

Reply | Threaded
Open this post in threaded view
|

Re: Does FreeBSD stack support multiple IP addresses?

Lambrecht Jürgen
In reply to this post by Grant Edwards-6
On 02/23/2016 04:59 PM, Grant Edwards wrote:

> On 2016-02-23, Lambrecht Jürgen <[hidden email]> wrote:
>> On 02/22/2016 04:05 PM, Grant Edwards wrote:
>>> When I tried it, the SIOCAIFADDR ioctl() let me set both address and
>>> netmask in a single call.  The "case SIOCAIFADDR" code falls through
>>> into SIOCSIFNETMASK code.  That didn't work for you?
>> Indeed, I remember now that I saw that in the code, but then you have
>> the netmask according to the class A/B/C rules, and that is not what we
>> want.
>>
>>>> - It is only possible to assign a class A/B/C netmask. CIDR netmasks are
>>>>     not possible.
>>> I think that's always been the case for this version of the stack,
>>> hasn't it?
>> Indeed.
> I just re-ran my tests and verified again that I'm able to set the IP
> and netmask in a single call to ioctl(SIOCAIFADDR).  In my tests, I
> tried:
>
>   Address         Netmask
> -----------      --------------
>   11.0.0.104      255.0.0.0
>   11.0.0.104      255.255.0.0
>   11.0.0.104      255.255.255.0
>   11.0.0.104      255.240.0.0
I don't understand how you can do those 3 above. The netmask is
calculated, and 11.0.0.104 is class A, so the netmask is 255.0.0.0
(IN_CLASSA_NET).
It is only possible to change the netmask by using the subnetmask, but
that is ANDed with the netmask, so you can only put bits to 0, not to 1!
See net/bsd_tcpip/current/src/sys/netinet/in.c, in_ifinit(ifp, ia, sin,
scrub):
     if (IN_CLASSA(i))
         ia->ia_netmask = IN_CLASSA_NET;
     else if (IN_CLASSB(i))
         ia->ia_netmask = IN_CLASSB_NET;
     else
         ia->ia_netmask = IN_CLASSC_NET;
     /*
      * The subnet mask usually includes at least the standard network part,
      * but may may be smaller in the case of supernetting.
      * If it is set, we believe it.
      */
     if (ia->ia_subnetmask == 0) {
         ia->ia_subnetmask = ia->ia_netmask;
         ia->ia_sockmask.sin_addr.s_addr = htonl(ia->ia_subnetmask);
     } else
         ia->ia_netmask &= ia->ia_subnetmask;


OK, now I see it: you use
   SIOCAIFADDR
we use
   SIOCSIFADDR
(from http://sourceware.org/ml/ecos-discuss/2005-08/msg00015.html)

Where did you learn to use SIOCAIFADDR?
Could you send me your application code? (then I can also try it)
Our code is below.

Because, when I read SIOCAIFADDR it still calls in_ifinit (but with ifra
instead of ifr (sin) and 0 instead of 1 (scrub, but in_ifscrub() is
called separately) arguments...
So I still don't understand it.
You _do_ use net/bsd_tcpip right?
Or you don't use *'AF_INET'*? (then it does not call in_ifinit())
Maybe in our application, we use SIOCSIFADDR wrong?

>   11.0.0.104      240.0.0.0
>   192.168.222.104 240.0.0.0
>   192.168.222.104 255.0.0.0
>   192.168.222.104 255.240.0.0
>   192.168.222.104 255.255.0.0
>   192.168.222.104 255.255.240.0
>   192.168.222.104 255.255.255.0
>   192.168.222.104 255.255.255.240
>
> In all cases, subsequent calls to show_network_tables() showed the IP
> address and netmask I requested in the ioctl() call and the correct
> corresponding broadcast address.
>
> I'm using an eCos snapshot from 2014.
I update regurarely, I also applied the patch of Bernd for raw sockets
and other fixes.
But that file bsd_tcpip/current/src/sys/netinet/in.c last change in CVS
is from 2009.

>
>>>>     I fixed current/src/sys/netinet/in.c for it, but I also adapted
>>>>     the ioctl to combine setting IP address and netmask in 1 call
>>>>     (so I cannot commit it back). Let me know if you want my fix.
> The current SIOCAIFADDR code works fine for me.
>
>> I changed a bit the use of the members of the "inet"-something
>> struct (in the ioctl call) to also use the netmask struct member
>> that is already in it. Because normally, when you call ioctl
>> SIOCSIFNETMASK separately, you specify the netmask in the same
>> struct member where you put the IP address for the SIOCAIFADDR call.
> But the SIOCAIFADDR call as a _separate_ place where you put the
> desired netmask, and AFIACT, that works.
Where? in.c::in_ifinit() as I say above (from the second
switch-case(SIOCAIFADDR)?

>
>> (I did a fast search in the linux code, but I am not used to that,
>> so I did not find the "Linux way")
>>
>>> I'm confused: based on my experiments and examination of the source
>>> code, it already works that way.
>>>
>> Well, it is both.  Indeed, as you say above, "code falls through
>> into SIOCSIFNETMASK code",
>> but then it sets "the netmask according to the class A/B/C rules",
>> so the netmask is _calculated_, not strictly _set_.  I am completely
>> sure about this, I read that whole code part.  (And my collegues did
>> the experimentation to set a 255.248.0.0 netmask resulting in a
>> 255.255.0.0 mask for 172.24.0.0 which is class B)
> I don't know what to tell you other than "it works fine for
> me". Unless the output from show_network_tables() is wrong...
>
No, I don't think so.
When I changed our SIOCSIFADDR code, I also saw the output of
show_network_tables() changing.


Here some code how we did the ioctl's (before I changed it).

   set_ip_address(ETH_INTERFACE, IP_ADDRESS);
   set_netmask_address(ETH_INTERFACE, NETMASK_ADDRESS);
   set_broadcast_address(ETH_INTERFACE, BROADCAST_ADDRESS);


TLV_BOOL set_ip_address(const char *interface, const char *ip_address)
{
   int test_sock;
   struct sockaddr_in* addr=NULL;
   struct ifreq ifr;

   test_sock = socket( AF_INET, SOCK_DGRAM, 0 );
   //This can also be another type of socket, see
http://ecos.sourceware.org/ml/ecos-discuss/2007-10/msg00012.html
   if( test_sock == -1 )
   {
     debug_printf("Cannot obtain IP sock\n");
     return TLV_FALSE;
   }

   memset(&ifr,0,sizeof( struct ifreq ) );
   strncpy(ifr.ifr_name,interface,IFNAMSIZ);
   //Delete old IP address, else there will be 2 IP addresses!
   if( ioctl( test_sock, SIOCGIFADDR, &ifr ) == -1 )
   {
     debug_printf("Cannot obtain IP address of %s:
%s\n",interface,strerror(errno));
   }
   else
   {
     if( ioctl( test_sock, SIOCDIFADDR, &ifr ) != 0 )
     {
       debug_printf("Cannot suppress old IP for %s:
%s\n",interface,strerror(errno));
     }
   }

   memset( &ifr, 0, sizeof( struct ifreq ) );
   addr= (struct sockaddr_in *)&(ifr.ifr_addr);
   memset(addr, 0, sizeof( struct sockaddr_in) );
   addr->sin_len=sizeof(struct sockaddr_in);
   addr->sin_family=AF_INET;
   addr->sin_addr.s_addr=inet_addr(ip_address);
   strncpy(ifr.ifr_name,interface,IFNAMSIZ);

   if( ioctl( test_sock, SIOCSIFADDR, &ifr ) != 0 )
   {
     debug_printf("Cannot set IP address of %s to %s:
%s\n",interface,ip_address,strerror(errno));
     close(test_sock);
     return TLV_FALSE;;
   }
   else
   {
     close(test_sock);
     return TLV_TRUE;
   }
}

TLV_BOOL set_netmask_address(const char* interface,const char * address)
{
  int test_sock=0;
  struct sockaddr_in* addr=NULL;
  struct sockaddr * addrp=NULL;
  struct ifreq ifr;

  memset( &ifr, 0, sizeof( struct ifreq ) );
  addrp = (struct sockaddr *)&(ifr.ifr_addr);
  addr= (struct sockaddr_in *)addrp;
  memset(addr, 0, sizeof( struct sockaddr) );
  addr->sin_len=sizeof(struct sockaddr_in);
  addr->sin_family=AF_INET;
  addr->sin_addr.s_addr=inet_addr(address);

  test_sock = socket( AF_INET, SOCK_DGRAM, 0 );
  if( test_sock == -1 )
  {
   diag_printf("Cannot obtain ip socket:%s",strerror(errno));
   return TLV_FALSE;
  }

  strncpy( ifr.ifr_name,interface,IFNAMSIZ);
  if( ioctl( test_sock, SIOCSIFNETMASK, &ifr ) == -1 )
  {
   diag_printf("Impossible to set netmask of interface '%s' to '%s':
'%s'",interface,address,strerror(errno));
   close(test_sock);
   return TLV_FALSE;
  }
close(test_sock);
  return TLV_TRUE;
}

TLV_BOOL set_broadcast_address(const char* interface,const char * address)
{
  int test_sock=0;
  struct sockaddr_in* addr=NULL;
  struct sockaddr * addrp=NULL;
  struct ifreq ifr;

  memset( &ifr, 0, sizeof( struct ifreq ) );
  addrp = (struct sockaddr *)&(ifr.ifr_addr);
  addr= (struct sockaddr_in *)addrp;
  memset(addr, 0, sizeof( struct sockaddr) );
  addr->sin_len=sizeof(struct sockaddr_in);
  addr->sin_family=AF_INET;
  addr->sin_addr.s_addr=inet_addr(address);

  test_sock = socket( AF_INET, SOCK_DGRAM, 0 );
  if( test_sock == -1 )
  {
   diag_printf("Cannot obtain ip socket:%s",strerror(errno));
   return TLV_FALSE;
  }

  strncpy( ifr.ifr_name,interface,IFNAMSIZ);
  if( ioctl( test_sock, SIOCSIFBRDADDR, &ifr ) == -1 )
  {
   diag_printf("Impossible to set broadcast of interface '%s' to '%s':
'%s'",interface,address,strerror(errno));
   close(test_sock);
   return TLV_FALSE;
  }
close(test_sock);
  return TLV_TRUE;
}


Kind regards,
Jürgen

--
Jürgen Lambrecht
R&D Associate
Mobile: +32 499 644 531
Twitter: JGRLambrecht
Tel: +32 (0)51 303045    Fax: +32 (0)51 310670
http://www.televic-rail.com
https://www.facebook.com/TelevicRail
Televic Rail NV - Leo Bekaertlaan 1 - 8870 Izegem - Belgium
Company number 0825.539.581 - RPR Kortrijk

This electronic transmission is intended exclusively for the person or entity
to whom it is addressed and may contain confidential and/or privileged
material. Any disclosure, copying, distribution or other action based upon the
information by persons or entities other than the intended recipient is
prohibited. All e-mail correspondence from Televic Rail NV is only intended for
information purposes and can not result in contractual obligations. Commitments
under Televic Rail NV can only occur through regular exchange of letters,
signed by authorized persons in accordance with publication in the Belgian
Official Gazette.
Reply | Threaded
Open this post in threaded view
|

Re: Does FreeBSD stack support multiple IP addresses?

Grant Edwards-6
On 2016-03-15, Lambrecht Jürgen <[hidden email]> wrote:
> On 02/23/2016 04:59 PM, Grant Edwards wrote:

>> I just re-ran my tests and verified again that I'm able to set the IP
>> and netmask in a single call to ioctl(SIOCAIFADDR).  In my tests, I
>> tried:
>>
>>   Address         Netmask
>> -----------      --------------
>>   11.0.0.104      255.0.0.0
>>   11.0.0.104      255.255.0.0
>>   11.0.0.104      255.255.255.0
>>   11.0.0.104      255.240.0.0

> OK, now I see it: you use
>    SIOCAIFADDR
> we use
>    SIOCSIFADDR
> (from http://sourceware.org/ml/ecos-discuss/2005-08/msg00015.html)

Yes.

> Where did you learn to use SIOCAIFADDR?

When I was writing a DHCPv6 implimentation, I had found some example
code somewhere that used SIOCAIFADDR_IN6.  So, I grepped the stack
source for SIOCAIFADDR.

Below is the function I was using during my testing.  The 's'
parameter is a UDP socket file descriptor.

   void addInterfaceAddress4(int s, uint32_t ip4addr, uint32_t netmask)
   {
     struct in_aliasreq ifra;
     struct sockaddr_in *addrp, *maskp;
   
     memset(&ifra, 0, sizeof ifra);
     strcpy(ifra.ifra_name, "eth0");
   
     addrp = (struct sockaddr_in *)  &ifra.ifra_addr;
     memset(addrp, 0, sizeof(*addrp));
     addrp->sin_family = AF_INET;
     addrp->sin_len = sizeof(*addrp);
     addrp->sin_port = 0;
   
     maskp = (struct sockaddr_in *)  &ifra.ifra_mask;
     memset(maskp, 0, sizeof(*maskp));
     maskp->sin_family = AF_INET;
     maskp->sin_len = sizeof(*maskp);
     maskp->sin_port = 0;
   
     addrp->sin_addr.s_addr = htonl(ip4addr);
     maskp->sin_addr.s_addr = htonl(netmask);
     if (ioctl(s, SIOCAIFADDR, &ifra))
       diag_printf("Error setting second 'eth0' IP address (SIOCAIFADDR): %s\n", strerror(errno));
   }


I just noticed that the memset(addrp,...) and memset(maskp,...) calls
are redundant (not needed).

--
Grant Edwards               grant.b.edwards        Yow! ... My pants just went
                                  at               on a wild rampage through a
                              gmail.com            Long Island Bowling Alley!!


--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss