Skip to content

Commit

Permalink
Unified TC API
Browse files Browse the repository at this point in the history
Finally got rid of all the qdisc/class/cls code duplication in
the tc module API. The API takes care of allocation/freeing the
tc object specific data.

I hope I got it right this time.
  • Loading branch information
tgraf committed Mar 21, 2011
1 parent 5dc897d commit 8eb5b55
Show file tree
Hide file tree
Showing 64 changed files with 2,142 additions and 3,079 deletions.
4 changes: 1 addition & 3 deletions include/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,18 @@ nobase_include_HEADERS = \
netlink/route/sch/sfq.h \
netlink/route/sch/tbf.h \
netlink/route/addr.h \
netlink/route/class-modules.h \
netlink/route/class.h \
netlink/route/classifier-modules.h \
netlink/route/classifier.h \
netlink/route/link.h \
netlink/route/neighbour.h \
netlink/route/neightbl.h \
netlink/route/nexthop.h \
netlink/route/qdisc-modules.h \
netlink/route/qdisc.h \
netlink/route/route.h \
netlink/route/rtnl.h \
netlink/route/rule.h \
netlink/route/tc.h \
netlink/route/tc-api.h \
netlink/socket.h \
netlink/types.h \
netlink/utils.h \
Expand Down
17 changes: 0 additions & 17 deletions include/netlink-tc.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,13 @@ extern "C" {

extern int tca_parse(struct nlattr **, int, struct rtnl_tc *,
struct nla_policy *);
extern int tca_msg_parser(struct nlmsghdr *, struct rtnl_tc *);
extern void tca_free_data(struct rtnl_tc *);
extern int tca_clone(struct rtnl_tc *, struct rtnl_tc *);
extern void tca_dump_line(struct rtnl_tc *, const char *,
struct nl_dump_params *);
extern void tca_dump_details(struct rtnl_tc *, struct nl_dump_params *);
extern void tca_dump_stats(struct rtnl_tc *, struct nl_dump_params *);
extern int tca_compare(struct nl_object *, struct nl_object *, uint32_t, int);

extern void tca_set_kind(struct rtnl_tc *, const char *);

extern int tca_build_msg(struct rtnl_tc *, int, int, struct nl_msg **);

#define RTNL_TC_RTABLE_SIZE 256

extern int rtnl_tc_build_rate_table(struct rtnl_tc *tc, struct rtnl_ratespec *,
uint32_t *);


static inline void *tca_priv(struct rtnl_tc *tca)
{
return tca->tc_subdata;
}

static inline void *tca_xstats(struct rtnl_tc *tca)
{
return tca->tc_xstats->d_data;
Expand Down
18 changes: 9 additions & 9 deletions include/netlink-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <netlink/route/qdisc.h>
#include <netlink/route/rtnl.h>
#include <netlink/route/route.h>
#include <netlink/route/tc-api.h>

#define NL_SOCK_BUFSIZE_SET (1<<0)
#define NL_SOCK_PASSCRED (1<<1)
Expand Down Expand Up @@ -441,7 +442,7 @@ struct rtnl_tstats

#define TCKINDSIZ 32

#define NL_TCA_GENERIC(pre) \
#define NL_TC_GENERIC(pre) \
NLHDR_COMMON \
uint32_t pre ##_family; \
uint32_t pre ##_ifindex; \
Expand All @@ -457,31 +458,30 @@ struct rtnl_tstats
uint64_t pre ##_stats[RTNL_TC_STATS_MAX+1]; \
struct nl_data * pre ##_xstats; \
struct nl_data * pre ##_subdata; \
struct rtnl_link * pre ##_link
struct rtnl_link * pre ##_link; \
struct rtnl_tc_ops * pre ##_ops; \
enum rtnl_tc_type pre ##_type

struct rtnl_tc
{
NL_TCA_GENERIC(tc);
NL_TC_GENERIC(tc);
};

struct rtnl_qdisc
{
NL_TCA_GENERIC(q);
struct rtnl_qdisc_ops *q_ops;
NL_TC_GENERIC(q);
};

struct rtnl_class
{
NL_TCA_GENERIC(c);
struct rtnl_class_ops *c_ops;
NL_TC_GENERIC(c);
};

struct rtnl_cls
{
NL_TCA_GENERIC(c);
NL_TC_GENERIC(c);
uint16_t c_prio;
uint16_t c_protocol;
struct rtnl_cls_ops *c_ops;
};

struct rtnl_u32
Expand Down
3 changes: 0 additions & 3 deletions include/netlink/cli/class.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@
#define __NETLINK_CLI_CLASS_H_

#include <netlink/route/class.h>
#include <netlink/route/class-modules.h>
#include <netlink/cli/tc.h>

extern struct rtnl_class *nl_cli_class_alloc(void);
extern struct nl_cache *nl_cli_class_alloc_cache(struct nl_sock *, int);

extern void nl_cli_class_parse_kind(struct rtnl_class *, char *);

#endif
15 changes: 0 additions & 15 deletions include/netlink/cli/cls.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,12 @@
#define __NETLINK_CLI_CLS_H_

#include <netlink/route/classifier.h>
#include <netlink/route/classifier-modules.h>
#include <netlink/cli/tc.h>

struct nl_cli_cls_module
{
const char * cm_name;
struct rtnl_cls_ops * cm_ops;
int (*cm_parse_argv)(struct rtnl_cls *, int, char **);
struct nl_list_head cm_list;
};

extern struct rtnl_cls * nl_cli_cls_alloc(void);
extern struct nl_cache * nl_cli_cls_alloc_cache(struct nl_sock *,
int, uint32_t);
extern void nl_cli_cls_parse_kind(struct rtnl_cls *, char *);
extern void nl_cli_cls_parse_proto(struct rtnl_cls *, char *);
extern struct rtnl_ematch_tree *nl_cli_cls_parse_ematch(struct rtnl_cls *, char *);

extern struct nl_cli_cls_module *nl_cli_cls_lookup(struct rtnl_cls_ops *);
extern void nl_cli_cls_register(struct nl_cli_cls_module *);
extern void nl_cli_cls_unregister(struct nl_cli_cls_module *);


#endif
20 changes: 1 addition & 19 deletions include/netlink/cli/qdisc.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,18 @@
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* Copyright (c) 2008-2010 Thomas Graf <tgraf@suug.ch>
* Copyright (c) 2008-2011 Thomas Graf <tgraf@suug.ch>
*/

#ifndef __NETLINK_CLI_QDISC_H_
#define __NETLINK_CLI_QDISC_H_

#include <netlink/route/qdisc.h>
#include <netlink/route/qdisc-modules.h>

#define nl_cli_qdisc_alloc_cache(sk) \
nl_cli_alloc_cache((sk), "queueing disciplines", \
rtnl_qdisc_alloc_cache)

struct nl_cli_qdisc_module
{
const char * qm_name;
struct rtnl_qdisc_ops * qm_ops;
struct rtnl_class_ops * qm_class_ops;
void (*qm_parse_qdisc_argv)(struct rtnl_qdisc *, int, char **);
void (*qm_parse_class_argv)(struct rtnl_class *, int, char **);
struct nl_list_head qm_list;
};

extern struct nl_cli_qdisc_module *nl_cli_qdisc_lookup(struct rtnl_qdisc_ops *);
extern struct nl_cli_qdisc_module *nl_cli_qdisc_lookup_by_class(struct rtnl_class_ops *);
extern void nl_cli_qdisc_register(struct nl_cli_qdisc_module *);
extern void nl_cli_qdisc_unregister(struct nl_cli_qdisc_module *);

extern struct rtnl_qdisc *nl_cli_qdisc_alloc(void);

extern void nl_cli_qdisc_parse_kind(struct rtnl_qdisc *, char *);

#endif
18 changes: 16 additions & 2 deletions include/netlink/cli/tc.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* Copyright (c) 2010 Thomas Graf <tgraf@suug.ch>
* Copyright (c) 2010-2011 Thomas Graf <tgraf@suug.ch>
*/

#ifndef __NETLINK_CLI_TC_H_
#define __NETLINK_CLI_TC_H_

#include <netlink/route/tc.h>
#include <netlink/route/tc-api.h>

extern void nl_cli_tc_parse_dev(struct rtnl_tc *, struct nl_cache *, char *);
extern void nl_cli_tc_parse_parent(struct rtnl_tc *, char *);
Expand All @@ -21,5 +21,19 @@ extern void nl_cli_tc_parse_mtu(struct rtnl_tc *, char *);
extern void nl_cli_tc_parse_mpu(struct rtnl_tc *, char *);
extern void nl_cli_tc_parse_overhead(struct rtnl_tc *, char *);
extern void nl_cli_tc_parse_linktype(struct rtnl_tc *, char *);
extern void nl_cli_tc_parse_kind(struct rtnl_tc *, char *);

struct nl_cli_tc_module
{
const char * tm_name;
enum rtnl_tc_type tm_type;
struct rtnl_tc_ops * tm_ops;
void (*tm_parse_argv)(struct rtnl_tc *, int, char **);
struct nl_list_head tm_list;
};

extern struct nl_cli_tc_module *nl_cli_tc_lookup(struct rtnl_tc_ops *);
extern void nl_cli_tc_register(struct nl_cli_tc_module *);
extern void nl_cli_tc_unregister(struct nl_cli_tc_module *);

#endif
73 changes: 0 additions & 73 deletions include/netlink/route/class-modules.h

This file was deleted.

2 changes: 0 additions & 2 deletions include/netlink/route/class.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ extern "C" {

struct rtnl_class;

extern struct nl_object_ops class_obj_ops;

extern struct rtnl_class * rtnl_class_alloc(void);
extern void rtnl_class_put(struct rtnl_class *);
extern int rtnl_class_alloc_cache(struct nl_sock *, int,
Expand Down
78 changes: 0 additions & 78 deletions include/netlink/route/classifier-modules.h

This file was deleted.

Loading

0 comments on commit 8eb5b55

Please sign in to comment.