Should we allow to configure twice the same IP?

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

Should we allow to configure twice the same IP?

Martin Pieuchot-2
There's nothing that prevent you to configure the same IPv4 address on
different interfaces in the same routing domain.  But does it make
sense?

Index: netinet/in.c
===================================================================
RCS file: /home/ncvs/src/sys/netinet/in.c,v
retrieving revision 1.106
diff -u -p -r1.106 in.c
--- netinet/in.c 7 Oct 2014 08:47:28 -0000 1.106
+++ netinet/in.c 28 Oct 2014 10:23:07 -0000
@@ -616,6 +616,10 @@ in_ifinit(struct ifnet *ifp, struct in_i
 
  splsoftassert(IPL_SOFTNET);
 
+ /* Make sure this address does not exist in the given rdomain. */
+ if (ifa_ifwithaddr(sintosa(sin), ifp->if_rdomain))
+ return (EEXIST);
+
  if (newaddr)
  TAILQ_INSERT_TAIL(&in_ifaddr, ia, ia_list);
 

Reply | Threaded
Open this post in threaded view
|

Re: Should we allow to configure twice the same IP?

Adam Thompson
On 14-10-28 05:55 AM, Martin Pieuchot wrote:

> There's nothing that prevent you to configure the same IPv4 address on
> different interfaces in the same routing domain.  But does it make
> sense?
>
> Index: netinet/in.c
> ===================================================================
> RCS file: /home/ncvs/src/sys/netinet/in.c,v
> retrieving revision 1.106
> diff -u -p -r1.106 in.c
> --- netinet/in.c 7 Oct 2014 08:47:28 -0000 1.106
> +++ netinet/in.c 28 Oct 2014 10:23:07 -0000
> @@ -616,6 +616,10 @@ in_ifinit(struct ifnet *ifp, struct in_i
>  
>   splsoftassert(IPL_SOFTNET);
>  
> + /* Make sure this address does not exist in the given rdomain. */
> + if (ifa_ifwithaddr(sintosa(sin), ifp->if_rdomain))
> + return (EEXIST);
> +
>   if (newaddr)
>   TAILQ_INSERT_TAIL(&in_ifaddr, ia, ia_list);

It might be needful when reconfiguring networks; if I swap two
interfaces' IP addresses in /etc/hostname.* and re-run /etc/netstart
instead of rebooting, I suspect this might break - I believe there would
be a very brief overlap where two interfaces had the same IP address.

Come to think of it, I'm not even sure whether this even works or not
as-is; any opinions on what would be the canonical approach to swapping
IPs between interfaces on a live system?  Just do it by hand?  Write
your own script?  Use netstart?  Or just reboot?

--
-Adam Thompson
  [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Should we allow to configure twice the same IP?

Martin Pieuchot-2
On 28/10/14(Tue) 08:57, Adam Thompson wrote:

> On 14-10-28 05:55 AM, Martin Pieuchot wrote:
> >There's nothing that prevent you to configure the same IPv4 address on
> >different interfaces in the same routing domain.  But does it make
> >sense?
> >
> >Index: netinet/in.c
> >===================================================================
> >RCS file: /home/ncvs/src/sys/netinet/in.c,v
> >retrieving revision 1.106
> >diff -u -p -r1.106 in.c
> >--- netinet/in.c 7 Oct 2014 08:47:28 -0000 1.106
> >+++ netinet/in.c 28 Oct 2014 10:23:07 -0000
> >@@ -616,6 +616,10 @@ in_ifinit(struct ifnet *ifp, struct in_i
> >   splsoftassert(IPL_SOFTNET);
> >+ /* Make sure this address does not exist in the given rdomain. */
> >+ if (ifa_ifwithaddr(sintosa(sin), ifp->if_rdomain))
> >+ return (EEXIST);
> >+
> >   if (newaddr)
> >   TAILQ_INSERT_TAIL(&in_ifaddr, ia, ia_list);
>
> It might be needful when reconfiguring networks; if I swap two interfaces'
> IP addresses in /etc/hostname.* and re-run /etc/netstart instead of
> rebooting, I suspect this might break - I believe there would be a very
> brief overlap where two interfaces had the same IP address.

The scenario you're describing is already broken :)  Did you try?

> Come to think of it, I'm not even sure whether this even works or not as-is;
> any opinions on what would be the canonical approach to swapping IPs between
> interfaces on a live system?  Just do it by hand?  Write your own script?
> Use netstart?  Or just reboot?

Nobody published a tool that would do that properly, so for the moment
do it by hand or reboot your machine.

Reply | Threaded
Open this post in threaded view
|

Re: Should we allow to configure twice the same IP?

Claudio Jeker
In reply to this post by Martin Pieuchot-2
On Tue, Oct 28, 2014 at 11:55:57AM +0100, Martin Pieuchot wrote:
> There's nothing that prevent you to configure the same IPv4 address on
> different interfaces in the same routing domain.  But does it make
> sense?

Yes, it does make sense. I abuse this feature to get unnumbered
point-to-point links.
 

> Index: netinet/in.c
> ===================================================================
> RCS file: /home/ncvs/src/sys/netinet/in.c,v
> retrieving revision 1.106
> diff -u -p -r1.106 in.c
> --- netinet/in.c 7 Oct 2014 08:47:28 -0000 1.106
> +++ netinet/in.c 28 Oct 2014 10:23:07 -0000
> @@ -616,6 +616,10 @@ in_ifinit(struct ifnet *ifp, struct in_i
>  
>   splsoftassert(IPL_SOFTNET);
>  
> + /* Make sure this address does not exist in the given rdomain. */
> + if (ifa_ifwithaddr(sintosa(sin), ifp->if_rdomain))
> + return (EEXIST);
> +
>   if (newaddr)
>   TAILQ_INSERT_TAIL(&in_ifaddr, ia, ia_list);
>  
>

--
:wq Claudio