Skip to content

Commit 4e902c5

Browse files
tgrafDavid S. Miller
authored andcommitted
[IPv4]: FIB configuration using struct fib_config
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 <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent ab32ea5 commit 4e902c5

File tree

8 files changed

+560
-468
lines changed

8 files changed

+560
-468
lines changed

include/net/ip_fib.h

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,32 @@
2020
#include <linux/seq_file.h>
2121
#include <net/fib_rules.h>
2222

23-
/* WARNING: The ordering of these elements must match ordering
24-
* of RTA_* rtnetlink attribute numbers.
25-
*/
26-
struct kern_rta {
27-
void *rta_dst;
28-
void *rta_src;
29-
int *rta_iif;
30-
int *rta_oif;
31-
void *rta_gw;
32-
u32 *rta_priority;
33-
void *rta_prefsrc;
34-
struct rtattr *rta_mx;
35-
struct rtattr *rta_mp;
36-
unsigned char *rta_protoinfo;
37-
u32 *rta_flow;
38-
struct rta_cacheinfo *rta_ci;
39-
struct rta_session *rta_sess;
40-
u32 *rta_mp_alg;
41-
};
23+
struct fib_config {
24+
u8 fc_family;
25+
u8 fc_dst_len;
26+
u8 fc_src_len;
27+
u8 fc_tos;
28+
u8 fc_protocol;
29+
u8 fc_scope;
30+
u8 fc_type;
31+
/* 1 byte unused */
32+
u32 fc_table;
33+
u32 fc_dst;
34+
u32 fc_src;
35+
u32 fc_gw;
36+
int fc_oif;
37+
u32 fc_flags;
38+
u32 fc_priority;
39+
u32 fc_prefsrc;
40+
struct nlattr *fc_mx;
41+
struct rtnexthop *fc_mp;
42+
int fc_mx_len;
43+
int fc_mp_len;
44+
u32 fc_flow;
45+
u32 fc_mp_alg;
46+
u32 fc_nlflags;
47+
struct nl_info fc_nlinfo;
48+
};
4249

4350
struct fib_info;
4451

@@ -154,12 +161,8 @@ struct fib_table {
154161
u32 tb_id;
155162
unsigned tb_stamp;
156163
int (*tb_lookup)(struct fib_table *tb, const struct flowi *flp, struct fib_result *res);
157-
int (*tb_insert)(struct fib_table *table, struct rtmsg *r,
158-
struct kern_rta *rta, struct nlmsghdr *n,
159-
struct netlink_skb_parms *req);
160-
int (*tb_delete)(struct fib_table *table, struct rtmsg *r,
161-
struct kern_rta *rta, struct nlmsghdr *n,
162-
struct netlink_skb_parms *req);
164+
int (*tb_insert)(struct fib_table *, struct fib_config *);
165+
int (*tb_delete)(struct fib_table *, struct fib_config *);
163166
int (*tb_dump)(struct fib_table *table, struct sk_buff *skb,
164167
struct netlink_callback *cb);
165168
int (*tb_flush)(struct fib_table *table);
@@ -228,8 +231,6 @@ struct rtentry;
228231
extern int ip_fib_check_default(u32 gw, struct net_device *dev);
229232
extern int fib_sync_down(u32 local, struct net_device *dev, int force);
230233
extern int fib_sync_up(struct net_device *dev);
231-
extern int fib_convert_rtentry(int cmd, struct nlmsghdr *nl, struct rtmsg *rtm,
232-
struct kern_rta *rta, struct rtentry *r);
233234
extern u32 __fib_res_prefsrc(struct fib_result *res);
234235

235236
/* Exported by fib_hash.c */

include/net/netlink.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,16 @@ struct nla_policy {
192192
u16 minlen;
193193
};
194194

195+
/**
196+
* struct nl_info - netlink source information
197+
* @nlh: Netlink message header of original request
198+
* @pid: Netlink PID of requesting application
199+
*/
200+
struct nl_info {
201+
struct nlmsghdr *nlh;
202+
u32 pid;
203+
};
204+
195205
extern void netlink_run_queue(struct sock *sk, unsigned int *qlen,
196206
int (*cb)(struct sk_buff *,
197207
struct nlmsghdr *, int *));

include/net/nexthop.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#ifndef __NET_NEXTHOP_H
2+
#define __NET_NEXTHOP_H
3+
4+
#include <linux/rtnetlink.h>
5+
#include <net/netlink.h>
6+
7+
static inline int rtnh_ok(const struct rtnexthop *rtnh, int remaining)
8+
{
9+
return remaining >= sizeof(*rtnh) &&
10+
rtnh->rtnh_len >= sizeof(*rtnh) &&
11+
rtnh->rtnh_len <= remaining;
12+
}
13+
14+
static inline struct rtnexthop *rtnh_next(const struct rtnexthop *rtnh,
15+
int *remaining)
16+
{
17+
int totlen = NLA_ALIGN(rtnh->rtnh_len);
18+
19+
*remaining -= totlen;
20+
return (struct rtnexthop *) ((char *) rtnh + totlen);
21+
}
22+
23+
static inline struct nlattr *rtnh_attrs(const struct rtnexthop *rtnh)
24+
{
25+
return (struct nlattr *) ((char *) rtnh + NLA_ALIGN(sizeof(*rtnh)));
26+
}
27+
28+
static inline int rtnh_attrlen(const struct rtnexthop *rtnh)
29+
{
30+
return rtnh->rtnh_len - NLA_ALIGN(sizeof(*rtnh));
31+
}
32+
33+
#endif

0 commit comments

Comments
 (0)