Skip to content

Commit

Permalink
[IPv4]: FIB configuration using struct fib_config
Browse files Browse the repository at this point in the history
Introduces struct fib_config replacing the ugly struct kern_rta
prone to ordering issues. Avoids creating faked netlink messages
for auto generated routes or requests via ioctl.

A new interface net/nexthop.h is added to help navigate through
nexthop configuration arrays.

A new struct nl_info will be used to carry the necessary netlink
information to be used for notifications later on.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
tgraf authored and David S. Miller committed Sep 22, 2006
1 parent ab32ea5 commit 4e902c5
Show file tree
Hide file tree
Showing 8 changed files with 560 additions and 468 deletions.
55 changes: 28 additions & 27 deletions include/net/ip_fib.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,32 @@
#include <linux/seq_file.h>
#include <net/fib_rules.h>

/* WARNING: The ordering of these elements must match ordering
* of RTA_* rtnetlink attribute numbers.
*/
struct kern_rta {
void *rta_dst;
void *rta_src;
int *rta_iif;
int *rta_oif;
void *rta_gw;
u32 *rta_priority;
void *rta_prefsrc;
struct rtattr *rta_mx;
struct rtattr *rta_mp;
unsigned char *rta_protoinfo;
u32 *rta_flow;
struct rta_cacheinfo *rta_ci;
struct rta_session *rta_sess;
u32 *rta_mp_alg;
};
struct fib_config {
u8 fc_family;
u8 fc_dst_len;
u8 fc_src_len;
u8 fc_tos;
u8 fc_protocol;
u8 fc_scope;
u8 fc_type;
/* 1 byte unused */
u32 fc_table;
u32 fc_dst;
u32 fc_src;
u32 fc_gw;
int fc_oif;
u32 fc_flags;
u32 fc_priority;
u32 fc_prefsrc;
struct nlattr *fc_mx;
struct rtnexthop *fc_mp;
int fc_mx_len;
int fc_mp_len;
u32 fc_flow;
u32 fc_mp_alg;
u32 fc_nlflags;
struct nl_info fc_nlinfo;
};

struct fib_info;

Expand Down Expand Up @@ -154,12 +161,8 @@ struct fib_table {
u32 tb_id;
unsigned tb_stamp;
int (*tb_lookup)(struct fib_table *tb, const struct flowi *flp, struct fib_result *res);
int (*tb_insert)(struct fib_table *table, struct rtmsg *r,
struct kern_rta *rta, struct nlmsghdr *n,
struct netlink_skb_parms *req);
int (*tb_delete)(struct fib_table *table, struct rtmsg *r,
struct kern_rta *rta, struct nlmsghdr *n,
struct netlink_skb_parms *req);
int (*tb_insert)(struct fib_table *, struct fib_config *);
int (*tb_delete)(struct fib_table *, struct fib_config *);
int (*tb_dump)(struct fib_table *table, struct sk_buff *skb,
struct netlink_callback *cb);
int (*tb_flush)(struct fib_table *table);
Expand Down Expand Up @@ -228,8 +231,6 @@ struct rtentry;
extern int ip_fib_check_default(u32 gw, struct net_device *dev);
extern int fib_sync_down(u32 local, struct net_device *dev, int force);
extern int fib_sync_up(struct net_device *dev);
extern int fib_convert_rtentry(int cmd, struct nlmsghdr *nl, struct rtmsg *rtm,
struct kern_rta *rta, struct rtentry *r);
extern u32 __fib_res_prefsrc(struct fib_result *res);

/* Exported by fib_hash.c */
Expand Down
10 changes: 10 additions & 0 deletions include/net/netlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,16 @@ struct nla_policy {
u16 minlen;
};

/**
* struct nl_info - netlink source information
* @nlh: Netlink message header of original request
* @pid: Netlink PID of requesting application
*/
struct nl_info {
struct nlmsghdr *nlh;
u32 pid;
};

extern void netlink_run_queue(struct sock *sk, unsigned int *qlen,
int (*cb)(struct sk_buff *,
struct nlmsghdr *, int *));
Expand Down
33 changes: 33 additions & 0 deletions include/net/nexthop.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef __NET_NEXTHOP_H
#define __NET_NEXTHOP_H

#include <linux/rtnetlink.h>
#include <net/netlink.h>

static inline int rtnh_ok(const struct rtnexthop *rtnh, int remaining)
{
return remaining >= sizeof(*rtnh) &&
rtnh->rtnh_len >= sizeof(*rtnh) &&
rtnh->rtnh_len <= remaining;
}

static inline struct rtnexthop *rtnh_next(const struct rtnexthop *rtnh,
int *remaining)
{
int totlen = NLA_ALIGN(rtnh->rtnh_len);

*remaining -= totlen;
return (struct rtnexthop *) ((char *) rtnh + totlen);
}

static inline struct nlattr *rtnh_attrs(const struct rtnexthop *rtnh)
{
return (struct nlattr *) ((char *) rtnh + NLA_ALIGN(sizeof(*rtnh)));
}

static inline int rtnh_attrlen(const struct rtnexthop *rtnh)
{
return rtnh->rtnh_len - NLA_ALIGN(sizeof(*rtnh));
}

#endif

0 comments on commit 4e902c5

Please sign in to comment.