From mboxrd@z Thu Jan 1 00:00:00 1970 From: Serhey Popovych Subject: [PATCH iproute2-next v2 6/8] ipl2tp: Use get_addr_rta() Date: Tue, 23 Jan 2018 21:19:28 +0200 Message-ID: <1516735170-20921-7-git-send-email-serhe.popovych@gmail.com> References: <1516735170-20921-1-git-send-email-serhe.popovych@gmail.com> To: netdev@vger.kernel.org Return-path: Received: from mail-lf0-f68.google.com ([209.85.215.68]:46430 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752058AbeAWTTo (ORCPT ); Tue, 23 Jan 2018 14:19:44 -0500 Received: by mail-lf0-f68.google.com with SMTP id q194so1995871lfe.13 for ; Tue, 23 Jan 2018 11:19:43 -0800 (PST) Received: from tuxracer.localdomain ([2a01:6d80::195:20:96:53]) by smtp.gmail.com with ESMTPSA id u87sm162394lfk.8.2018.01.23.11.19.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Jan 2018 11:19:41 -0800 (PST) In-Reply-To: <1516735170-20921-1-git-send-email-serhe.popovych@gmail.com> Sender: netdev-owner@vger.kernel.org List-ID: Signed-off-by: Serhey Popovych --- 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