netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Serhey Popovych <serhe.popovych@gmail.com>
To: netdev@vger.kernel.org
Subject: [PATCH iproute2-next v2 6/8] ipl2tp: Use get_addr_rta()
Date: Tue, 23 Jan 2018 21:19:28 +0200	[thread overview]
Message-ID: <1516735170-20921-7-git-send-email-serhe.popovych@gmail.com> (raw)
In-Reply-To: <1516735170-20921-1-git-send-email-serhe.popovych@gmail.com>

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
---
 ip/ipl2tp.c |   37 ++++++++++++++++---------------------
 1 file changed, 16 insertions(+), 21 deletions(-)

diff --git a/ip/ipl2tp.c b/ip/ipl2tp.c
index 7c5ed31..8aaee74 100644
--- a/ip/ipl2tp.c
+++ b/ip/ipl2tp.c
@@ -296,7 +296,7 @@ static int get_response(struct nlmsghdr *n, void *arg)
 	struct l2tp_data *data = arg;
 	struct l2tp_parm *p = &data->config;
 	struct rtattr *attrs[L2TP_ATTR_MAX + 1];
-	struct rtattr *nla_stats;
+	struct rtattr *nla_stats, *rta;
 	int len;
 
 	/* Validate message and parse attributes */
@@ -352,30 +352,25 @@ static int get_response(struct nlmsghdr *n, void *arg)
 
 	if (attrs[L2TP_ATTR_RECV_TIMEOUT])
 		p->reorder_timeout = rta_getattr_u64(attrs[L2TP_ATTR_RECV_TIMEOUT]);
-	if (attrs[L2TP_ATTR_IP_SADDR]) {
-		p->local_ip.family = AF_INET;
-		p->local_ip.data[0] = rta_getattr_u32(attrs[L2TP_ATTR_IP_SADDR]);
-		p->local_ip.bytelen = 4;
-		p->local_ip.bitlen = -1;
-	}
-	if (attrs[L2TP_ATTR_IP_DADDR]) {
-		p->peer_ip.family = AF_INET;
-		p->peer_ip.data[0] = rta_getattr_u32(attrs[L2TP_ATTR_IP_DADDR]);
-		p->peer_ip.bytelen = 4;
-		p->peer_ip.bitlen = -1;
-	}
-	if (attrs[L2TP_ATTR_IP6_SADDR]) {
+
+	rta = attrs[L2TP_ATTR_IP_SADDR];
+	p->local_ip.family = AF_INET;
+	if (!rta) {
+		rta = attrs[L2TP_ATTR_IP6_SADDR];
 		p->local_ip.family = AF_INET6;
-		memcpy(&p->local_ip.data, RTA_DATA(attrs[L2TP_ATTR_IP6_SADDR]),
-			p->local_ip.bytelen = 16);
-		p->local_ip.bitlen = -1;
 	}
-	if (attrs[L2TP_ATTR_IP6_DADDR]) {
+	if (rta && get_addr_rta(&p->local_ip, rta, p->local_ip.family))
+		return -1;
+
+	rta = attrs[L2TP_ATTR_IP_DADDR];
+	p->peer_ip.family = AF_INET;
+	if (!rta) {
+		rta = attrs[L2TP_ATTR_IP6_DADDR];
 		p->peer_ip.family = AF_INET6;
-		memcpy(&p->peer_ip.data, RTA_DATA(attrs[L2TP_ATTR_IP6_DADDR]),
-			p->peer_ip.bytelen = 16);
-		p->peer_ip.bitlen = -1;
 	}
+	if (rta && get_addr_rta(&p->peer_ip, rta, p->peer_ip.family))
+		return -1;
+
 	if (attrs[L2TP_ATTR_UDP_SPORT])
 		p->local_udp_port = rta_getattr_u16(attrs[L2TP_ATTR_UDP_SPORT]);
 	if (attrs[L2TP_ATTR_UDP_DPORT])
-- 
1.7.10.4

  parent reply	other threads:[~2018-01-23 19:19 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-23 19:19 [PATCH iproute2-next v2 0/8] ip: Introduce and use get_addr_rta()/inet_addr_match_rta() Serhey Popovych
2018-01-23 19:19 ` [PATCH iproute2-next v2 1/8] utils: Introduce get_addr_rta() and inet_addr_match_rta() Serhey Popovych
2018-01-23 19:19 ` [PATCH iproute2-next v2 2/8] ipaddress: Use inet_addr_match_rta() Serhey Popovych
2018-01-23 19:19 ` [PATCH iproute2-next v2 3/8] iprule: " Serhey Popovych
2018-01-23 19:19 ` [PATCH iproute2-next v2 4/8] ipmroute: " Serhey Popovych
2018-01-23 19:19 ` [PATCH iproute2-next v2 5/8] ipneigh: " Serhey Popovych
2018-01-23 19:19 ` Serhey Popovych [this message]
2018-01-23 19:19 ` [PATCH iproute2-next v2 7/8] tcp_metric: Use get_addr_rta() Serhey Popovych
2018-01-23 19:19 ` [PATCH iproute2-next v2 8/8] ip/tunnel: Unify local/remote endpoint address printing Serhey Popovych
2018-01-24 18:40   ` David Ahern
2018-01-24  3:45 ` [PATCH iproute2-next v2 0/8] ip: Introduce and use get_addr_rta()/inet_addr_match_rta() 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=1516735170-20921-7-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;
as well as URLs for NNTP newsgroup(s).