From patchwork Thu Apr 25 11:04:40 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 239494 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 61F232C0092 for ; Thu, 25 Apr 2013 21:04:54 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757863Ab3DYLEu (ORCPT ); Thu, 25 Apr 2013 07:04:50 -0400 Received: from na3sys010aog104.obsmtp.com ([74.125.245.76]:56793 "HELO na3sys010aog104.obsmtp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1755522Ab3DYLEs (ORCPT ); Thu, 25 Apr 2013 07:04:48 -0400 Received: from mail-lb0-f200.google.com ([209.85.217.200]) (using TLSv1) by na3sys010aob104.postini.com ([74.125.244.12]) with SMTP ID DSNKUXkNz3CfuI1P3ca8h45Day4cjnsPrig4@postini.com; Thu, 25 Apr 2013 04:04:48 PDT Received: by mail-lb0-f200.google.com with SMTP id t12so4076847lbi.7 for ; Thu, 25 Apr 2013 04:04:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-received:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state; bh=vYSjmPnBNMCfcOEq/mkIhyqnnwWSdKna6qPNXyjfIZg=; b=oKzCREg04scAl+v9RhMwgTqjVda84+BSpPShToi/GZ5casN8nHclK0ucgZOmxClt+U jN9uCDl/c+s812lMggPJHvkl2wCTMclz0uJzXiYL7oHQBDoQis2cd7XyE9s7AwWmskjf NiaR0nPp6P8LiS4V7hk+Xg3cTeWACJ9Zwfm7PFLn+x8jqnV+DXMn4jjOrdG4OOInR/S6 PwLUTtxqCX86b5a8vygX1ZAWuJEX8zB4oeiqOJu1CBcE47Ps3g0WPidouHskOkdiS9L1 0dlf2L+RkmyxB/xTvscLgbTltPvldhVfan9bn17aU9RM9116Xl3yB+kCQ2qnj647mans G3fg== X-Received: by 10.180.24.69 with SMTP id s5mr40850529wif.34.1366887886441; Thu, 25 Apr 2013 04:04:46 -0700 (PDT) X-Received: by 10.180.24.69 with SMTP id s5mr40850515wif.34.1366887886345; Thu, 25 Apr 2013 04:04:46 -0700 (PDT) Received: from mike.rapoport@ravellosystems.com (93-172-42-194.bb.netvision.net.il. [93.172.42.194]) by mx.google.com with ESMTPSA id ed6sm10023725wib.9.2013.04.25.04.04.43 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 25 Apr 2013 04:04:45 -0700 (PDT) Received: by mike.rapoport@ravellosystems.com (sSMTP sendmail emulation); Thu, 25 Apr 2013 14:04:42 +0300 From: Mike Rapoport To: netdev@vger.kernel.org Cc: Mike Rapoport Subject: [PATCH iproute2] vxlan: allow specifying multiple default destinations Date: Thu, 25 Apr 2013 14:04:40 +0300 Message-Id: <1366887880-4045-1-git-send-email-mike.rapoport@ravellosystems.com> X-Mailer: git-send-email 1.8.1.5 In-Reply-To: <1366887829-3950-1-git-send-email-mike.rapoport@ravellosystems.com> References: <1366887829-3950-1-git-send-email-mike.rapoport@ravellosystems.com> X-Gm-Message-State: ALoCoQlbm4DHQperbrLTg4Sqqr+spMRHa77w9ATy6zdKMQRI92PZGe4sQntJMYkal1bBuOqT4Ls7Yq0DcM2OFYrsG3Pj/gSmmOcym1asjEAm5XedXICKCrnVZdl/IRBNbLT5oIkfULKQWQYkukO+xmcY5a/w9URlxzVn8hnbtF4CoLenQLtxS4A= Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Signed-off-by: Mike Rapoport --- This patch depends on the pending changes to ip/iplink_vxlan.c as as well as on IPv6 support in vxlan. I'll rebase and resend it once all the changes to vxlan are merged. ip/iplink_vxlan.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/ip/iplink_vxlan.c b/ip/iplink_vxlan.c index 661ab9e..9ba5a1d 100644 --- a/ip/iplink_vxlan.c +++ b/ip/iplink_vxlan.c @@ -28,11 +28,56 @@ static void explain(void) fprintf(stderr, " [ port MIN MAX ] [ [no]learning ]\n"); fprintf(stderr, " [ [no]proxy ] [ [no]rsc ]\n"); fprintf(stderr, " [ [no]l2miss ] [ [no]l3miss ]\n"); + fprintf(stderr, " [ dstadd DST ]\n"); + fprintf(stderr, " [ dstdel ADDR ]\n"); fprintf(stderr, "\n"); fprintf(stderr, "Where: VNI := 0-16777215\n"); fprintf(stderr, " ADDR := { IP_ADDRESS | any }\n"); fprintf(stderr, " TOS := { NUMBER | inherit }\n"); fprintf(stderr, " TTL := { 1..255 | inherit }\n"); + fprintf(stderr, " DST := [ ADDR [port PORT] [vni VNI] [via DEV]]\n"); +} + +static int vxlan_parse_dst(int *argcp, char ***argvp, struct nlmsghdr *n) +{ + int argc = *argcp; + char **argv = *argvp; + __u32 vni, port, ifindex; + struct rtattr *tail; + + tail = NLMSG_TAIL(n); + addattr_l(n, 1024, IFLA_VXLAN_REMOTE_ADD, NULL, 0); + + while (argc > 0) { + if (!matches(*argv, "vni")) { + NEXT_ARG(); + if (get_u32(&vni, *argv, 0) || + vni >= 1u << 24) + invarg("invalid id", *argv); + addattr32(n, 1024, IFLA_VXLAN_REMOTE_VNI, vni); + } else if (!matches(*argv, "port")) { + NEXT_ARG(); + if (get_u32(&port, *argv, 0)) + invarg("port", *argv); + addattr32(n, 1024, IFLA_VXLAN_REMOTE_PORT, port); + } else if (!matches(*argv, "via")) { + NEXT_ARG(); + ifindex = if_nametoindex(*argv); + addattr32(n, 1024, IFLA_VXLAN_REMOTE_IFINDEX, ifindex); + } else { + inet_prefix addr; + get_prefix(&addr, *argv, AF_UNSPEC); + addattr_l(n, 1024, IFLA_VXLAN_REMOTE_ADDR, + &addr.data, addr.bytelen); + } + argc--, argv++; + } + + tail->rta_len = (void *) NLMSG_TAIL(n) - (void *)tail; + + *argcp = argc; + *argvp = argv; + return 0; } static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv, @@ -56,6 +101,7 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv, __u32 age = 0; __u32 maxaddr = 0; struct ifla_vxlan_port_range range = { 0, 0 }; + inet_prefix *remote_del = NULL; while (argc > 0) { if (!matches(*argv, "id") || @@ -138,6 +184,14 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv, invarg("max port", *argv); range.low = htons(minport); range.high = htons(maxport); + } else if (!matches(*argv, "dstadd")) { + NEXT_ARG(); + vxlan_parse_dst(&argc, &argv, n); + } else if (!matches(*argv, "dstdel")) { + inet_prefix addr; + NEXT_ARG(); + get_prefix(&addr, *argv, AF_UNSPEC); + remote_del = &addr; } else if (!matches(*argv, "nolearning")) { learning = 0; } else if (!matches(*argv, "learning")) { @@ -202,10 +256,37 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, char **argv, if (range.low || range.high) addattr_l(n, 1024, IFLA_VXLAN_PORT_RANGE, &range, sizeof(range)); + if (remote_del) + addattr_l(n, 1024, IFLA_VXLAN_REMOTE_DEL, remote_del->data, + remote_del->bytelen); return 0; } +static void vxlan_print_remotes(FILE *f, struct rtattr *attr) +{ + struct rtattr *i; + char s1[1024]; + int rem, n = 0; + + fprintf(f, "\n default destinations :\n"); + + rem = RTA_PAYLOAD(attr); + for (i = RTA_DATA(attr); RTA_OK(i, rem); i = RTA_NEXT(i, rem), n++) { + if (RTA_PAYLOAD(i) >= sizeof(struct in6_addr)) { + struct in6_addr addr; + memcpy(&addr, RTA_DATA(i), sizeof(struct in6_addr)); + fprintf(f, " %s\n", + format_host(AF_INET6, sizeof(struct in6_addr), + &addr, s1, sizeof(s1))); + } else if (RTA_PAYLOAD(i) >= sizeof(__be32)) { + __be32 addr = rta_getattr_u32(i); + fprintf(f, " %s\n", + format_host(AF_INET, 4, &addr, s1, sizeof(s1))); + } + } +} + static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) { __u32 vni; @@ -308,6 +389,9 @@ static void vxlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) if (tb[IFLA_VXLAN_LIMIT] && (maxaddr = rta_getattr_u32(tb[IFLA_VXLAN_LIMIT]) != 0)) fprintf(f, "maxaddr %u ", maxaddr); + + if (tb[IFLA_VXLAN_REMOTE_LST]) + vxlan_print_remotes(f, tb[IFLA_VXLAN_REMOTE_LST]); } struct link_util vxlan_link_util = {