Move nlbuf onto stack and don't share a single buffer for sending
and receiving. Move nlportid into client state structure.
This commit is contained in:
parent
659aafaec8
commit
e990246207
@ -38,6 +38,7 @@ struct client_state_t {
|
||||
int ifsPrevState;
|
||||
int listenMode;
|
||||
int epollFd, signalFd, listenFd, arpFd, nlFd;
|
||||
int nlPortId;
|
||||
uint32_t clientAddr, serverAddr, routerAddr;
|
||||
uint32_t lease, renewTime, rebindTime, xid;
|
||||
uint8_t routerArp[6], serverArp[6];
|
||||
|
@ -75,6 +75,7 @@ struct client_state_t cs = {
|
||||
.listenFd = -1,
|
||||
.arpFd = -1,
|
||||
.nlFd = -1,
|
||||
.nlPortId = -1,
|
||||
.routerArp = "\0\0\0\0\0\0",
|
||||
.serverArp = "\0\0\0\0\0\0",
|
||||
};
|
||||
@ -349,7 +350,7 @@ int main(int argc, char **argv)
|
||||
write_pid(pidfile);
|
||||
}
|
||||
|
||||
if ((cs.nlFd = nl_open(NETLINK_ROUTE, RTMGRP_LINK, &nlportid)) < 0) {
|
||||
if ((cs.nlFd = nl_open(NETLINK_ROUTE, RTMGRP_LINK, &cs.nlPortId)) < 0) {
|
||||
log_line("FATAL - failed to open netlink socket");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
@ -42,9 +42,6 @@
|
||||
#include "nl.h"
|
||||
#include "state.h"
|
||||
|
||||
static char nlbuf[8192];
|
||||
int nlportid;
|
||||
|
||||
static int nlrtattr_assign(struct nlattr *attr, int type, void *data)
|
||||
{
|
||||
struct nlattr **tb = data;
|
||||
@ -124,22 +121,24 @@ static int nl_process_msgs(const struct nlmsghdr *nlh, void *data)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Destroys contents of nlbuf */
|
||||
void handle_nl_message(struct client_state_t *cs)
|
||||
{
|
||||
char nlbuf[8192];
|
||||
ssize_t ret;
|
||||
assert(cs->nlFd != -1);
|
||||
do {
|
||||
ret = nl_recv_buf(cs->nlFd, nlbuf, sizeof nlbuf);
|
||||
if (ret == -1)
|
||||
break;
|
||||
if (nl_foreach_nlmsg(nlbuf, ret, nlportid, nl_process_msgs, cs) == -1)
|
||||
if (nl_foreach_nlmsg(nlbuf, ret, cs->nlPortId, nl_process_msgs, cs)
|
||||
== -1)
|
||||
break;
|
||||
} while (ret > 0);
|
||||
}
|
||||
|
||||
static int nl_sendgetlink(struct client_state_t *cs)
|
||||
{
|
||||
char nlbuf[8192];
|
||||
struct nlmsghdr *nlh = (struct nlmsghdr *)nlbuf;
|
||||
|
||||
memset(nlbuf, 0, sizeof nlbuf);
|
||||
|
@ -40,8 +40,6 @@ enum {
|
||||
IFS_REMOVED
|
||||
};
|
||||
|
||||
extern int nlportid;
|
||||
|
||||
void handle_nl_message(struct client_state_t *cs);
|
||||
int nl_getifdata(struct client_state_t *cs);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user