summaryrefslogtreecommitdiff
path: root/src/network.c
diff options
context:
space:
mode:
author/C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org </C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org>2007-05-18 19:33:40 +0000
committer/C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org </C=EU/ST=EU/CN=Pablo Neira Ayuso/emailAddress=pablo@netfilter.org>2007-05-18 19:33:40 +0000
commit2932c6b8e6952ae84b221b854b43810c61e5c8fa (patch)
tree1ee7f364f74f2dff2b462ab01868a74fd87f1403 /src/network.c
parent34d1c62cd414a6d3321d9a51fc6e1d61f36da2f0 (diff)
downloadconntrack-tools-2932c6b8e6952ae84b221b854b43810c61e5c8fa.tar.gz
conntrack-tools-2932c6b8e6952ae84b221b854b43810c61e5c8fa.zip
- remove dead code sync-mode.c
- flush nack queue in the conntrackd -f path - do not increase add_fail counter for EEXIST errors - cleanup sync-nack code - improve mcast_recv_netmsg: sanity check before checksumming!
Diffstat (limited to 'src/network.c')
-rw-r--r--src/network.c47
1 files changed, 33 insertions, 14 deletions
diff --git a/src/network.c b/src/network.c
index b9be318..51e89c7 100644
--- a/src/network.c
+++ b/src/network.c
@@ -70,7 +70,7 @@ int mcast_resend_netmsg(struct mcast_sock *m, void *data)
{
struct nlnetwork *net = data;
struct nlmsghdr *nlh = data + sizeof(struct nlnetwork);
- unsigned int len = htonl(nlh->nlmsg_len) + sizeof(struct nlnetwork);
+ unsigned int len;
net->flags = ntohs(net->flags);
@@ -80,10 +80,10 @@ int mcast_resend_netmsg(struct mcast_sock *m, void *data)
net->flags |= NET_HELLO;
}
- if (net->flags & NET_NACK || net->flags & NET_ACK) {
- struct nlnetwork_ack *nack = (struct nlnetwork_ack *) net;
+ if (net->flags & NET_NACK || net->flags & NET_ACK)
len = sizeof(struct nlnetwork_ack);
- }
+ else
+ len = sizeof(struct nlnetwork) + ntohl(nlh->nlmsg_len);
net->flags = htons(net->flags);
net->seq = htonl(cur_seq++);
@@ -147,32 +147,44 @@ int mcast_recv_netmsg(struct mcast_sock *m, void *data, int len)
if (ret <= 0)
return ret;
+ /* message too small: no room for the header */
if (ret < sizeof(struct nlnetwork))
return -1;
- if (!valid_checksum(data, ret))
- return -1;
-
- net->flags = ntohs(net->flags);
- net->seq = ntohl(net->seq);
-
- if (net->flags & NET_HELLO)
- STATE_SYNC(last_seq_recv) = net->seq-1;
+ if (ntohs(net->flags) & NET_HELLO)
+ STATE_SYNC(last_seq_recv) = ntohl(net->seq) - 1;
- if (net->flags & NET_NACK || net->flags & NET_ACK) {
+ if (ntohs(net->flags) & NET_NACK || ntohs(net->flags) & NET_ACK) {
struct nlnetwork_ack *nack = (struct nlnetwork_ack *) net;
+ /* message too small: no room for the header */
if (ret < sizeof(struct nlnetwork_ack))
return -1;
+ if (!valid_checksum(data, ret))
+ return -1;
+
+ /* host byte order conversion */
+ net->flags = ntohs(net->flags);
+ net->seq = ntohl(net->seq);
+
+ /* acknowledgement conversion */
nack->from = ntohl(nack->from);
nack->to = ntohl(nack->to);
return ret;
}
- if (net->flags & NET_RESYNC)
+ if (ntohs(net->flags) & NET_RESYNC) {
+ if (!valid_checksum(data, ret))
+ return -1;
+
+ /* host byte order conversion */
+ net->flags = ntohs(net->flags);
+ net->seq = ntohl(net->seq);
+
return ret;
+ }
/* information received is too small */
if (ret < NLMSG_SPACE(sizeof(struct nfgenmsg)))
@@ -197,6 +209,13 @@ int mcast_recv_netmsg(struct mcast_sock *m, void *data, int len)
if (nfhdr->version != NFNETLINK_V0)
return -1;
+ if (!valid_checksum(data, ret))
+ return -1;
+
+ /* host byte order conversion */
+ net->flags = ntohs(net->flags);
+ net->seq = ntohl(net->seq);
+
if (nlh_network2host(nlh) == -1)
return -1;