diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2020-08-03 00:25:44 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2020-08-03 00:35:14 +0900 |
commit | 794ad99854c0484294410676d119622ed82fe7d4 (patch) | |
tree | 4d438e2df32c38cb2a6c151bbc2e7fdc208b6d23 | |
parent | c0e1f534c95f5f395fda62b01ea1c245323e3aed (diff) | |
download | bird-794ad99854c0484294410676d119622ed82fe7d4.tar.gz |
Netlink: Allocate static sized buffer for netlink message
The current logic to calculate the required buffer size to construct a
netlink message is erroneous in many ways.
Use a static sized buffer to simplify things.
FIXME: this change is not complete and has a serious bug - if the
constructed message happens to be larger than 8192 bytes, BIRD will
hit bug() and crash.
-rw-r--r-- | sysdep/linux/netlink.c | 20 |
1 files changed, 5 insertions, 15 deletions
diff --git a/sysdep/linux/netlink.c b/sysdep/linux/netlink.c index f85bcf35..f5719547 100644 --- a/sysdep/linux/netlink.c +++ b/sysdep/linux/netlink.c @@ -128,7 +128,8 @@ struct nl_sock uint last_size; }; -#define NL_RX_SIZE 8192 +#define NL_RX_SIZE 32768 +#define NL_TX_SIZE 8192 #define NL_OP_DELETE 0 #define NL_OP_ADD (NLM_F_CREATE|NLM_F_EXCL) @@ -1207,15 +1208,6 @@ krt_capable(rte *e) } } -static inline int -nh_bufsize(struct nexthop *nh) -{ - int rv = 0; - for (; nh != NULL; nh = nh->next) - rv += RTNH_LENGTH(RTA_LENGTH(sizeof(ip_addr))); - return rv; -} - static int nl_send_route(struct krt_proto *p, rte *e, int op, int dest, struct nexthop *nh) { @@ -1223,17 +1215,15 @@ nl_send_route(struct krt_proto *p, rte *e, int op, int dest, struct nexthop *nh) net *net = e->net; rta *a = e->attrs; ea_list *eattrs = a->eattrs; - int bufsize = 128 + KRT_METRICS_MAX*8 + nh_bufsize(&(a->nh)); u32 priority = 0; struct { struct nlmsghdr h; struct rtmsg r; - char buf[0]; - } *r; + char buf[NL_TX_SIZE]; + } _r, *r = &_r; - int rsize = sizeof(*r) + bufsize; - r = alloca(rsize); + int rsize = sizeof(_r); DBG("nl_send_route(%N,op=%x)\n", net->n.addr, op); |