From: Serhey Popovych <serhe.popovych@gmail.com>
To: netdev@vger.kernel.org
Subject: [PATCH iproute2 4/6] iplink_geneve: Get rid of inet_get_addr()
Date: Thu, 18 Jan 2018 20:13:45 +0200 [thread overview]
Message-ID: <1516299227-26724-5-git-send-email-serhe.popovych@gmail.com> (raw)
In-Reply-To: <1516299227-26724-1-git-send-email-serhe.popovych@gmail.com>
Now we have additional information about address
class from get_addr() we can use it in place of
inet_get_addr().
Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
---
ip/iplink_geneve.c | 23 ++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)
diff --git a/ip/iplink_geneve.c b/ip/iplink_geneve.c
index f0f1d1c..2b97e7a 100644
--- a/ip/iplink_geneve.c
+++ b/ip/iplink_geneve.c
@@ -57,9 +57,8 @@ static void check_duparg(__u64 *attrs, int type, const char *key,
static int geneve_parse_opt(struct link_util *lu, int argc, char **argv,
struct nlmsghdr *n)
{
+ inet_prefix daddr;
__u32 vni = 0;
- __u32 daddr = 0;
- struct in6_addr daddr6 = IN6ADDR_ANY_INIT;
__u32 label = 0;
__u8 ttl = 0;
__u8 tos = 0;
@@ -72,6 +71,8 @@ static int geneve_parse_opt(struct link_util *lu, int argc, char **argv,
bool set_op = (n->nlmsg_type == RTM_NEWLINK &&
!(n->nlmsg_flags & NLM_F_CREATE));
+ daddr.flags = 0;
+
while (argc > 0) {
if (!matches(*argv, "id") ||
!matches(*argv, "vni")) {
@@ -84,11 +85,8 @@ static int geneve_parse_opt(struct link_util *lu, int argc, char **argv,
NEXT_ARG();
check_duparg(&attrs, IFLA_GENEVE_REMOTE, "remote",
*argv);
- if (!inet_get_addr(*argv, &daddr, &daddr6)) {
- fprintf(stderr, "Invalid address \"%s\"\n", *argv);
- return -1;
- }
- if (IN6_IS_ADDR_MULTICAST(&daddr6) || IN_MULTICAST(ntohl(daddr)))
+ get_addr(&daddr, *argv, AF_UNSPEC);
+ if (!is_addrtype_inet_not_multi(&daddr))
invarg("invalid remote address", *argv);
} else if (!matches(*argv, "ttl") ||
!matches(*argv, "hoplimit")) {
@@ -191,18 +189,17 @@ static int geneve_parse_opt(struct link_util *lu, int argc, char **argv,
* ID (VNI) to identify the geneve device, and we do not need
* the remote IP.
*/
- if (!set_op && !daddr && IN6_IS_ADDR_UNSPECIFIED(&daddr6)) {
+ if (!set_op && !is_addrtype_inet(&daddr)) {
fprintf(stderr, "geneve: remote link partner not specified\n");
return -1;
}
}
addattr32(n, 1024, IFLA_GENEVE_ID, vni);
- if (daddr)
- addattr_l(n, 1024, IFLA_GENEVE_REMOTE, &daddr, 4);
- if (!IN6_IS_ADDR_UNSPECIFIED(&daddr6)) {
- addattr_l(n, 1024, IFLA_GENEVE_REMOTE6, &daddr6,
- sizeof(struct in6_addr));
+ if (is_addrtype_inet(&daddr)) {
+ int type = (daddr.family == AF_INET) ? IFLA_GENEVE_REMOTE :
+ IFLA_GENEVE_REMOTE6;
+ addattr_l(n, sizeof(1024), type, daddr.data, daddr.bytelen);
}
if (!set_op || GENEVE_ATTRSET(attrs, IFLA_GENEVE_LABEL))
addattr32(n, 1024, IFLA_GENEVE_LABEL, label);
--
1.7.10.4
next prev parent reply other threads:[~2018-01-18 18:14 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-18 18:13 [PATCH iproute2 0/6] utils: Get rid of inet_get_addr() Serhey Popovych
2018-01-18 18:13 ` [PATCH iproute2 1/6] utils: Always specify family for address in get_addr_1() Serhey Popovych
2018-01-18 18:13 ` [PATCH iproute2 2/6] utils: Always specify family and ->bytelen in get_prefix_1() Serhey Popovych
2018-01-18 18:13 ` [PATCH iproute2 3/6] utils: Fast inet address classification after get_addr() Serhey Popovych
2018-01-18 18:13 ` Serhey Popovych [this message]
2018-01-18 18:13 ` [PATCH iproute2 5/6] iplink_vxlan: Get rid of inet_get_addr() Serhey Popovych
2018-01-18 18:13 ` [PATCH iproute2 6/6] ip: " Serhey Popovych
2018-01-18 18:35 ` [PATCH iproute2 0/6] utils: " Stephen Hemminger
2018-01-21 18:13 ` David Ahern
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1516299227-26724-5-git-send-email-serhe.popovych@gmail.com \
--to=serhe.popovych@gmail.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox