]> granicus.if.org Git - libnl/commitdiff
route/act: add skbedit action
authorCong Wang <xiyou.wangcong@gmail.com>
Wed, 28 Jan 2015 23:19:18 +0000 (15:19 -0800)
committerThomas Haller <thaller@redhat.com>
Mon, 2 Feb 2015 17:16:11 +0000 (18:16 +0100)
[thaller@redhat.com: changed whitespace and libnl-route.sym]

Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
include/Makefile.am
include/linux-private/linux/tc_act/tc_skbedit.h [new file with mode: 0644]
include/netlink-private/types.h
include/netlink/route/act/skbedit.h [new file with mode: 0644]
lib/Makefile.am
lib/route/act/skbedit.c [new file with mode: 0644]
libnl-route-3.sym

index 6592995c7e1ed2fa47a3162d1d94b47a137b68d7..bf86ed1fda77d9a69f42aa3f4d082ef8774ebcff 100644 (file)
@@ -33,6 +33,7 @@ nobase_libnlinclude_HEADERS = \
        netlink/object.h \
        netlink/route/action.h \
        netlink/route/act/mirred.h \
+       netlink/route/act/skbedit.h \
        netlink/route/cls/ematch/cmp.h \
        netlink/route/cls/ematch/meta.h \
        netlink/route/cls/ematch/nbyte.h \
@@ -148,6 +149,7 @@ noinst_HEADERS = \
        linux-private/linux/pkt_cls.h \
        linux-private/linux/sock_diag.h \
        linux-private/linux/tc_act/tc_mirred.h \
+       linux-private/linux/tc_act/tc_skbedit.h \
        linux-private/linux/pkt_sched.h \
        linux-private/linux/rtnetlink.h \
        linux-private/linux/snmp.h \
diff --git a/include/linux-private/linux/tc_act/tc_skbedit.h b/include/linux-private/linux/tc_act/tc_skbedit.h
new file mode 100644 (file)
index 0000000..7a2e910
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2008, Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place - Suite 330, Boston, MA 02111-1307 USA.
+ *
+ * Author: Alexander Duyck <alexander.h.duyck@intel.com>
+ */
+
+#ifndef __LINUX_TC_SKBEDIT_H
+#define __LINUX_TC_SKBEDIT_H
+
+#include <linux/pkt_cls.h>
+
+#define TCA_ACT_SKBEDIT 11
+
+#define SKBEDIT_F_PRIORITY             0x1
+#define SKBEDIT_F_QUEUE_MAPPING                0x2
+#define SKBEDIT_F_MARK                 0x4
+
+struct tc_skbedit {
+       tc_gen;
+};
+
+enum {
+       TCA_SKBEDIT_UNSPEC,
+       TCA_SKBEDIT_TM,
+       TCA_SKBEDIT_PARMS,
+       TCA_SKBEDIT_PRIORITY,
+       TCA_SKBEDIT_QUEUE_MAPPING,
+       TCA_SKBEDIT_MARK,
+       __TCA_SKBEDIT_MAX
+};
+#define TCA_SKBEDIT_MAX (__TCA_SKBEDIT_MAX - 1)
+
+#endif
index b4dc8acb5f2b094cbf8f6e9bb4fabfde106d4fcb..6d5cc7f97111b1c00320e287dd055f0891c47215 100644 (file)
@@ -22,6 +22,7 @@
 #include <netlink/netfilter/ct.h>
 #include <netlink-private/route/tc-api.h>
 #include <linux/tc_act/tc_mirred.h>
+#include <linux/tc_act/tc_skbedit.h>
 
 #define NL_SOCK_BUFSIZE_SET    (1<<0)
 #define NL_SOCK_PASSCRED       (1<<1)
@@ -520,6 +521,15 @@ struct rtnl_mirred
        struct tc_mirred m_parm;
 };
 
+struct rtnl_skbedit
+{
+       struct tc_skbedit s_parm;
+       uint32_t          s_flags;
+       uint32_t          s_mark;
+       uint32_t          s_prio;
+       uint16_t          s_queue_mapping;
+};
+
 struct rtnl_u32
 {
        uint32_t                cu_divisor;
diff --git a/include/netlink/route/act/skbedit.h b/include/netlink/route/act/skbedit.h
new file mode 100644 (file)
index 0000000..69829e8
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * netlink/route/act/skbedit.h skbedit action
+ *
+ *     This library is free software; you can redistribute it and/or
+ *     modify it under the terms of the GNU Lesser General Public
+ *     License as published by the Free Software Foundation version 2.1
+ *     of the License.
+ *
+ * Copyright (c) 2015 Cong Wang <xiyou.wangcong@gmail.com>
+ */
+
+#ifndef NETLINK_SKBEDIT_H_
+#define NETLINK_SKBEDIT_H_
+
+#include <netlink/netlink.h>
+#include <netlink/cache.h>
+#include <netlink/route/action.h>
+#include <linux/tc_act/tc_skbedit.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern int rtnl_skbedit_set_action(struct rtnl_act *act, int action);
+extern int rtnl_skbedit_get_action(struct rtnl_act *act);
+extern int rtnl_skbedit_set_queue_mapping(struct rtnl_act *act, uint16_t index);
+extern int rtnl_skbedit_get_queue_mapping(struct rtnl_act *act, uint16_t *index);
+extern int rtnl_skbedit_set_mark(struct rtnl_act *act, uint32_t mark);
+extern int rtnl_skbedit_get_mark(struct rtnl_act *act, uint32_t *mark);
+extern int rtnl_skbedit_set_priority(struct rtnl_act *act, uint32_t prio);
+extern int rtnl_skbedit_get_priority(struct rtnl_act *act, uint32_t *prio);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
index f193c29ec6440db55e7810ea2db7776800ef215f..12a793a42df2904169aa041f1062da29ef2920e9 100644 (file)
@@ -94,6 +94,7 @@ libnl_route_3_la_SOURCES = \
        route/cls/cgroup.c \
        \
        route/act/mirred.c \
+       route/act/skbedit.c \
        \
        route/cls/ematch.c \
        route/cls/ematch/container.c route/cls/ematch/cmp.c \
diff --git a/lib/route/act/skbedit.c b/lib/route/act/skbedit.c
new file mode 100644 (file)
index 0000000..d85265e
--- /dev/null
@@ -0,0 +1,290 @@
+/*
+ * lib/route/act/skbedit.c             skbedit action
+ *
+ *     This library is free software; you can redistribute it and/or
+ *     modify it under the terms of the GNU Lesser General Public
+ *     License as published by the Free Software Foundation version 2.1
+ *     of the License.
+ *
+ * Copyright (c) 2015 Cong Wang <xiyou.wangcong@gmail.com>
+ */
+
+/**
+ * @ingroup act
+ * @defgroup act_skbedit SKB Editing
+ *
+ * @{
+ */
+
+#include <netlink-private/netlink.h>
+#include <netlink-private/tc.h>
+#include <netlink/netlink.h>
+#include <netlink/attr.h>
+#include <netlink/utils.h>
+#include <netlink-private/route/tc-api.h>
+#include <netlink/route/act/skbedit.h>
+
+static struct nla_policy skbedit_policy[TCA_SKBEDIT_MAX + 1] = {
+       [TCA_SKBEDIT_PARMS]             = { .minlen = sizeof(struct tc_skbedit) },
+       [TCA_SKBEDIT_PRIORITY]          = { .type = NLA_U32 },
+       [TCA_SKBEDIT_QUEUE_MAPPING]     = { .type = NLA_U16 },
+       [TCA_SKBEDIT_MARK]              = { .type = NLA_U32 },
+};
+
+static int skbedit_msg_parser(struct rtnl_tc *tc, void *data)
+{
+       struct rtnl_skbedit *u = data;
+       struct nlattr *tb[TCA_SKBEDIT_MAX + 1];
+       int err;
+
+       err = tca_parse(tb, TCA_SKBEDIT_MAX, tc, skbedit_policy);
+       if (err < 0)
+               return err;
+
+       if (!tb[TCA_SKBEDIT_PARMS])
+               return -NLE_MISSING_ATTR;
+
+       u->s_flags = 0;
+       if (tb[TCA_SKBEDIT_PRIORITY] != NULL) {
+               u->s_flags |= SKBEDIT_F_PRIORITY;
+               u->s_prio = nla_get_u32(tb[TCA_SKBEDIT_PRIORITY]);
+       }
+
+       if (tb[TCA_SKBEDIT_QUEUE_MAPPING] != NULL) {
+               u->s_flags |= SKBEDIT_F_QUEUE_MAPPING;
+               u->s_queue_mapping = nla_get_u16(tb[TCA_SKBEDIT_QUEUE_MAPPING]);
+       }
+
+       if (tb[TCA_SKBEDIT_MARK] != NULL) {
+               u->s_flags |= SKBEDIT_F_MARK;
+               u->s_mark = nla_get_u32(tb[TCA_SKBEDIT_MARK]);
+       }
+
+       return 0;
+}
+
+static void skbedit_free_data(struct rtnl_tc *tc, void *data)
+{
+}
+
+static int skbedit_clone(void *_dst, void *_src)
+{
+       struct rtnl_skbedit *dst = _dst, *src = _src;
+
+       memcpy(dst, src, sizeof(*src));
+       return 0;
+}
+
+static void skbedit_dump_line(struct rtnl_tc *tc, void *data,
+                         struct nl_dump_params *p)
+{
+       struct rtnl_skbedit *u = data;
+
+       if (!u)
+               return;
+
+       if (u->s_flags & SKBEDIT_F_PRIORITY)
+               nl_dump(p, " priority %u", u->s_prio);
+
+       if (u->s_flags & SKBEDIT_F_MARK)
+               nl_dump(p, " mark %u", u->s_mark);
+
+       if (u->s_flags & SKBEDIT_F_QUEUE_MAPPING)
+               nl_dump(p, " queue_mapping %u", u->s_queue_mapping);
+
+       switch(u->s_parm.action){
+       case TC_ACT_UNSPEC:
+               nl_dump(p, " unspecified");
+               break;
+       case TC_ACT_PIPE:
+               nl_dump(p, " pipe");
+               break;
+       case TC_ACT_STOLEN:
+               nl_dump(p, " stolen");
+               break;
+       case TC_ACT_SHOT:
+               nl_dump(p, " shot");
+               break;
+       case TC_ACT_QUEUED:
+               nl_dump(p, " queued");
+               break;
+       case TC_ACT_REPEAT:
+               nl_dump(p, " repeat");
+               break;
+       }
+}
+
+static void skbedit_dump_details(struct rtnl_tc *tc, void *data,
+                            struct nl_dump_params *p)
+{
+}
+
+static void skbedit_dump_stats(struct rtnl_tc *tc, void *data,
+                          struct nl_dump_params *p)
+{
+       struct rtnl_skbedit *u = data;
+
+       if (!u)
+               return;
+       /* TODO */
+}
+
+
+static int skbedit_msg_fill(struct rtnl_tc *tc, void *data, struct nl_msg *msg)
+{
+       struct rtnl_skbedit *u = data;
+
+       if (!u)
+               return 0;
+
+       NLA_PUT(msg, TCA_SKBEDIT_PARMS, sizeof(u->s_parm), &u->s_parm);
+
+       if (u->s_flags & SKBEDIT_F_MARK)
+               NLA_PUT_U32(msg, TCA_SKBEDIT_MARK, u->s_mark);
+
+       if (u->s_flags & SKBEDIT_F_PRIORITY)
+               NLA_PUT_U32(msg, TCA_SKBEDIT_PRIORITY, u->s_prio);
+
+       if (u->s_flags & SKBEDIT_F_QUEUE_MAPPING)
+               NLA_PUT_U32(msg, TCA_SKBEDIT_QUEUE_MAPPING, u->s_queue_mapping);
+
+       return 0;
+
+nla_put_failure:
+       return -NLE_NOMEM;
+}
+
+/**
+ * @name Attribute Modifications
+ * @{
+ */
+
+int rtnl_skbedit_set_action(struct rtnl_act *act, int action)
+{
+       struct rtnl_skbedit *u;
+
+       if (!(u = (struct rtnl_skbedit *) rtnl_tc_data(TC_CAST(act))))
+               return -NLE_NOMEM;
+
+       if (action > TC_ACT_REPEAT || action < TC_ACT_UNSPEC)
+               return -NLE_INVAL;
+
+       u->s_parm.action = action;
+       return 0;
+}
+
+int rtnl_skbedit_get_action(struct rtnl_act *act)
+{
+       struct rtnl_skbedit *u;
+
+       if (!(u = (struct rtnl_skbedit *) rtnl_tc_data(TC_CAST(act))))
+               return -NLE_NOMEM;
+       return u->s_parm.action;
+}
+
+int rtnl_skbedit_set_queue_mapping(struct rtnl_act *act, uint16_t index)
+{
+       struct rtnl_skbedit *u;
+
+       if (!(u = (struct rtnl_skbedit *) rtnl_tc_data(TC_CAST(act))))
+               return -NLE_NOMEM;
+
+       u->s_queue_mapping = index;
+       u->s_flags |= SKBEDIT_F_QUEUE_MAPPING;
+       return 0;
+}
+
+int rtnl_skbedit_get_queue_mapping(struct rtnl_act *act, uint16_t *index)
+{
+       struct rtnl_skbedit *u;
+
+       u = (struct rtnl_skbedit *) rtnl_tc_data(TC_CAST(act));
+       if (!u)
+               return -NLE_NOMEM;
+       if (!(u->s_flags & SKBEDIT_F_QUEUE_MAPPING))
+               return -NLE_NOATTR;
+
+       *index = u->s_queue_mapping;
+       return 0;
+}
+
+int rtnl_skbedit_set_mark(struct rtnl_act *act, uint32_t mark)
+{
+       struct rtnl_skbedit *u;
+
+       if (!(u = (struct rtnl_skbedit *) rtnl_tc_data(TC_CAST(act))))
+               return -NLE_NOMEM;
+
+       u->s_mark = mark;
+       u->s_flags |= SKBEDIT_F_MARK;
+       return 0;
+}
+
+int rtnl_skbedit_get_mark(struct rtnl_act *act, uint32_t *mark)
+{
+       struct rtnl_skbedit *u;
+
+       u = (struct rtnl_skbedit *) rtnl_tc_data(TC_CAST(act));
+       if (!u)
+               return -NLE_NOMEM;
+       if (!(u->s_flags & SKBEDIT_F_MARK))
+               return -NLE_NOATTR;
+
+       *mark = u->s_mark;
+       return 0;
+}
+
+int rtnl_skbedit_set_priority(struct rtnl_act *act, uint32_t prio)
+{
+       struct rtnl_skbedit *u;
+
+       if (!(u = (struct rtnl_skbedit *) rtnl_tc_data(TC_CAST(act))))
+               return -NLE_NOMEM;
+
+       u->s_prio = prio;
+       u->s_flags |= SKBEDIT_F_PRIORITY;
+       return 0;
+}
+
+int rtnl_skbedit_get_priority(struct rtnl_act *act, uint32_t *prio)
+{
+       struct rtnl_skbedit *u;
+
+       u = (struct rtnl_skbedit *) rtnl_tc_data(TC_CAST(act));
+       if (!u)
+               return -NLE_NOMEM;
+       if (!(u->s_flags & SKBEDIT_F_PRIORITY))
+               return -NLE_NOATTR;
+
+       *prio = u->s_prio;
+       return 0;
+}
+
+/** @} */
+
+static struct rtnl_tc_ops skbedit_ops = {
+       .to_kind                = "skbedit",
+       .to_type                = RTNL_TC_TYPE_ACT,
+       .to_size                = sizeof(struct rtnl_skbedit),
+       .to_msg_parser          = skbedit_msg_parser,
+       .to_free_data           = skbedit_free_data,
+       .to_clone               = skbedit_clone,
+       .to_msg_fill            = skbedit_msg_fill,
+       .to_dump = {
+           [NL_DUMP_LINE]      = skbedit_dump_line,
+           [NL_DUMP_DETAILS]   = skbedit_dump_details,
+           [NL_DUMP_STATS]     = skbedit_dump_stats,
+       },
+};
+
+static void __init skbedit_init(void)
+{
+       rtnl_tc_register(&skbedit_ops);
+}
+
+static void __exit skbedit_exit(void)
+{
+       rtnl_tc_unregister(&skbedit_ops);
+}
+
+/** @} */
index 7ce2e3852a52fc44faa9fd2e8ff076ea5b3128ff..a0ca051e0522fac4ab02c5e9760202221e3cc08a 100644 (file)
@@ -842,6 +842,14 @@ global:
        rtnl_link_inet6_str2addrgenmode;
        rtnl_qdisc_hfsc_get_defcls;
        rtnl_qdisc_hfsc_set_defcls;
+       rtnl_skbedit_get_action;
+       rtnl_skbedit_get_mark;
+       rtnl_skbedit_get_priority;
+       rtnl_skbedit_get_queue_mapping;
+       rtnl_skbedit_set_action;
+       rtnl_skbedit_set_mark;
+       rtnl_skbedit_set_priority;
+       rtnl_skbedit_set_queue_mapping;
        rtnl_u32_add_mark;
        rtnl_u32_del_mark;
 } libnl_3;