* add ip to interface as primary ip address, not secondary ip when there is alreadly primary ip?
@ 2013-09-17 22:31 Vincent Li
2013-09-18 0:29 ` Cong Wang
0 siblings, 1 reply; 5+ messages in thread
From: Vincent Li @ 2013-09-17 22:31 UTC (permalink / raw)
To: netdev@vger.kernel.org
Hi,
we need to add more than one ip address to one interface, but want to
be able to specify which ip address to be primary and which to be
secondary (be deterministic) , what we have found out is that the
first ip address added to the interface will be always the primary ip
address, the primary or secondary is depending on which ip get added
to the interface first.
we could also delete an existing primary ip address, then the
secondary ip will be promoted to primary.
ideally though, we would like to have the capability in
kernel/userspace to specify a flag or something to add any ip as
primary even if there is already existing primary ip address (could
downgrade the existing primary to secondary ip). does this make sense
?
Vincent
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: add ip to interface as primary ip address, not secondary ip when there is alreadly primary ip?
2013-09-17 22:31 add ip to interface as primary ip address, not secondary ip when there is alreadly primary ip? Vincent Li
@ 2013-09-18 0:29 ` Cong Wang
2013-09-19 16:54 ` Vincent Li
0 siblings, 1 reply; 5+ messages in thread
From: Cong Wang @ 2013-09-18 0:29 UTC (permalink / raw)
To: netdev
On Tue, 17 Sep 2013 at 22:31 GMT, Vincent Li <vincent.mc.li@gmail.com> wrote:
>
> ideally though, we would like to have the capability in
> kernel/userspace to specify a flag or something to add any ip as
> primary even if there is already existing primary ip address (could
> downgrade the existing primary to secondary ip). does this make sense
> ?
'ip addr' already has flags for this.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: add ip to interface as primary ip address, not secondary ip when there is alreadly primary ip?
2013-09-18 0:29 ` Cong Wang
@ 2013-09-19 16:54 ` Vincent Li
2013-09-20 2:28 ` Cong Wang
0 siblings, 1 reply; 5+ messages in thread
From: Vincent Li @ 2013-09-19 16:54 UTC (permalink / raw)
To: Cong Wang; +Cc: netdev@vger.kernel.org
thanks for the pointer
'ip addr' indeed has flag IFA_F_SECONDARY for this, but it is not
available for 'ip addr add', so I made a simple patch for iproute2
ip/ipaddress.c as below:
diff --git a/ip/ipaddress.c b/ip/ipaddress.c
index 1c3e4da..b5aa96a 100644
--- a/ip/ipaddress.c
+++ b/ip/ipaddress.c
@@ -1307,6 +1307,11 @@ static int ipaddr_modify(int cmd, int flags,
int argc, char **argv)
invarg("invalid scope value.", *argv);
req.ifa.ifa_scope = scope;
scoped = 1;
+ } else if (strcmp(*argv, "secondary") == 0 ||
+ strcmp(*argv, "temporary") == 0) {
+ req.ifa.ifa_flags |= IFA_F_SECONDARY;
+ } else if (strcmp(*argv, "primary") == 0) {
+ req.ifa.ifa_flags &= ~IFA_F_SECONDARY;
} else if (strcmp(*argv, "dev") == 0) {
NEXT_ARG();
d = *argv;
I also found that I need to patch up the kernel and here is the kernel
patch, it might look silly, but it works as I tested
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index a1b5bcb..2a1d61b 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -440,14 +440,18 @@ static int __inet_insert_ifa(struct in_ifaddr
*ifa, struct nlmsghdr *nlh,
return 0;
}
- ifa->ifa_flags &= ~IFA_F_SECONDARY;
last_primary = &in_dev->ifa_list;
for (ifap = &in_dev->ifa_list; (ifa1 = *ifap) != NULL;
ifap = &ifa1->ifa_next) {
if (!(ifa1->ifa_flags & IFA_F_SECONDARY) &&
- ifa->ifa_scope <= ifa1->ifa_scope)
- last_primary = &ifa1->ifa_next;
+ ifa->ifa_scope <= ifa1->ifa_scope) {
+ if (ifa->ifa_flags & IFA_F_SECONDARY) {
+ last_primary = &ifa1->ifa_next;
+ } else {
+ ifa1->ifa_flags |= IFA_F_SECONDARY;
+ }
+ }
if (ifa1->ifa_mask == ifa->ifa_mask &&
inet_ifa_match(ifa1->ifa_address, ifa)) {
if (ifa1->ifa_local == ifa->ifa_local) {
@@ -458,7 +462,11 @@ static int __inet_insert_ifa(struct in_ifaddr
*ifa, struct nlmsghdr *nlh,
inet_free_ifa(ifa);
return -EINVAL;
}
- ifa->ifa_flags |= IFA_F_SECONDARY;
+ if (ifa->ifa_flags & IFA_F_SECONDARY) {
+ ifa->ifa_flags |= IFA_F_SECONDARY;
+ } else {
+ ifa->ifa_flags &= ~IFA_F_SECONDARY;
+ }
}
}
my test steps:
1
./ip/ip addr add 192.168.1.1/24 scope global secondary dev eth0
./ip/ip adrr show eth0 >> /tmp/ipaddr.txt
2
./ip/ip addr add 192.168.1.2/24 scope global primary dev eth0
./ip/ip addr show eth0 >> /tmp/ipaddr.txt
3
./ip/ip addr add 192.168.1.3/24 scope global primary dev eth0
./ip/ip addr show eth0 >> /tmp/ipaddr.txt
4
./ip/ip addr add 192.168.1.4/24 scope global secondary dev eth0
./ip/ip addr show eth0 >> /tmp/ipaddr.txt
5
./ip/ip addr add 192.168.1.5/24 scope global dev eth0
./ip/ip addr show eth0 >> /tmp/ipaddr.txt
6
./ip/ip addr del 192.168.1.5/24 dev eth0
./ip/ip addr show eth0 >> /tmp/ipaddr.txt
test result for each step
result 1
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast
state UP group default qlen 1000
link/ether 52:54:00:e3:8f:33 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.1/24 scope global secondary eth0
valid_lft forever preferred_lft forever
inet6 fe80::5054:ff:fee3:8f33/64 scope link
valid_lft forever preferred_lft forever
result 2
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast
state UP group default qlen 1000
link/ether 52:54:00:e3:8f:33 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.2/24 scope global eth0
valid_lft forever preferred_lft forever
inet 192.168.1.1/24 scope global secondary eth0
valid_lft forever preferred_lft forever
inet6 fe80::5054:ff:fee3:8f33/64 scope link
valid_lft forever preferred_lft forever
result 3
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast
state UP group default qlen 1000
link/ether 52:54:00:e3:8f:33 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.3/24 scope global eth0
valid_lft forever preferred_lft forever
inet 192.168.1.2/24 scope global secondary eth0
valid_lft forever preferred_lft forever
inet 192.168.1.1/24 scope global secondary eth0
valid_lft forever preferred_lft forever
inet6 fe80::5054:ff:fee3:8f33/64 scope link
valid_lft forever preferred_lft forever
result 4
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast
state UP group default qlen 1000
link/ether 52:54:00:e3:8f:33 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.3/24 scope global eth0
valid_lft forever preferred_lft forever
inet 192.168.1.2/24 scope global secondary eth0
valid_lft forever preferred_lft forever
inet 192.168.1.1/24 scope global secondary eth0
valid_lft forever preferred_lft forever
inet 192.168.1.4/24 scope global secondary eth0
valid_lft forever preferred_lft forever
inet6 fe80::5054:ff:fee3:8f33/64 scope link
valid_lft forever preferred_lft forever
result 5
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast
state UP group default qlen 1000
link/ether 52:54:00:e3:8f:33 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.5/24 scope global eth0
valid_lft forever preferred_lft forever
inet 192.168.1.3/24 scope global secondary eth0
valid_lft forever preferred_lft forever
inet 192.168.1.2/24 scope global secondary eth0
valid_lft forever preferred_lft forever
inet 192.168.1.1/24 scope global secondary eth0
valid_lft forever preferred_lft forever
inet 192.168.1.4/24 scope global secondary eth0
valid_lft forever preferred_lft forever
inet6 fe80::5054:ff:fee3:8f33/64 scope link
valid_lft forever preferred_lft forever
result 6
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast
state UP group default qlen 1000
link/ether 52:54:00:e3:8f:33 brd ff:ff:ff:ff:ff:ff
inet6 fe80::5054:ff:fee3:8f33/64 scope link
valid_lft forever preferred_lft forever
it does seems to achieve what I wanted, any comment on this?
On Tue, Sep 17, 2013 at 5:29 PM, Cong Wang <xiyou.wangcong@gmail.com> wrote:
> On Tue, 17 Sep 2013 at 22:31 GMT, Vincent Li <vincent.mc.li@gmail.com> wrote:
>>
>> ideally though, we would like to have the capability in
>> kernel/userspace to specify a flag or something to add any ip as
>> primary even if there is already existing primary ip address (could
>> downgrade the existing primary to secondary ip). does this make sense
>> ?
>
> 'ip addr' already has flags for this.
>
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: add ip to interface as primary ip address, not secondary ip when there is alreadly primary ip?
2013-09-19 16:54 ` Vincent Li
@ 2013-09-20 2:28 ` Cong Wang
2013-09-20 3:53 ` Vincent Li
0 siblings, 1 reply; 5+ messages in thread
From: Cong Wang @ 2013-09-20 2:28 UTC (permalink / raw)
To: netdev
On Thu, 19 Sep 2013 at 16:54 GMT, Vincent Li <vincent.mc.li@gmail.com> wrote:
> thanks for the pointer
>
> 'ip addr' indeed has flag IFA_F_SECONDARY for this, but it is not
> available for 'ip addr add', so I made a simple patch for iproute2
> ip/ipaddress.c as below:
% git grep secondary ip/ipaddress.c
ip/ipaddress.c: fprintf(stderr, "FLAG := [ permanent | dynamic |
secondary | primary |\n");
ip/ipaddress.c: fprintf(fp, "secondary ");
ip/ipaddress.c:static int print_addrinfo_secondary(const struct
sockaddr_nl *who,
ip/ipaddress.c: .filter =
print_addrinfo_secondary,
ip/ipaddress.c: } else if (strcmp(*argv, "secondary") == 0 ||
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: add ip to interface as primary ip address, not secondary ip when there is alreadly primary ip?
2013-09-20 2:28 ` Cong Wang
@ 2013-09-20 3:53 ` Vincent Li
0 siblings, 0 replies; 5+ messages in thread
From: Vincent Li @ 2013-09-20 3:53 UTC (permalink / raw)
To: Cong Wang; +Cc: netdev@vger.kernel.org
yes, I found them too, they are for 'ip addr show' or 'ip addr list'
though, not for 'ip addr add' unless I am missing something obvious.
care to clarify further ?
Vincent
On Thu, Sep 19, 2013 at 7:28 PM, Cong Wang <xiyou.wangcong@gmail.com> wrote:
> On Thu, 19 Sep 2013 at 16:54 GMT, Vincent Li <vincent.mc.li@gmail.com> wrote:
>> thanks for the pointer
>>
>> 'ip addr' indeed has flag IFA_F_SECONDARY for this, but it is not
>> available for 'ip addr add', so I made a simple patch for iproute2
>> ip/ipaddress.c as below:
>
> % git grep secondary ip/ipaddress.c
> ip/ipaddress.c: fprintf(stderr, "FLAG := [ permanent | dynamic |
> secondary | primary |\n");
> ip/ipaddress.c: fprintf(fp, "secondary ");
> ip/ipaddress.c:static int print_addrinfo_secondary(const struct
> sockaddr_nl *who,
> ip/ipaddress.c: .filter =
> print_addrinfo_secondary,
> ip/ipaddress.c: } else if (strcmp(*argv, "secondary") == 0 ||
>
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-09-20 3:53 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-17 22:31 add ip to interface as primary ip address, not secondary ip when there is alreadly primary ip? Vincent Li
2013-09-18 0:29 ` Cong Wang
2013-09-19 16:54 ` Vincent Li
2013-09-20 2:28 ` Cong Wang
2013-09-20 3:53 ` Vincent Li
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).