summaryrefslogtreecommitdiff
path: root/ctdb/common
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2018-08-17 12:30:19 +1000
committerAmitay Isaacs <amitay@samba.org>2018-08-30 04:48:58 +0200
commit8fcf1af559f2a716ebcfb8277668d6539fd432f0 (patch)
tree037bb842ea294d4d75aaca1e459aface19c2f02a /ctdb/common
parenta02cba1c8a716d8e939d9bfb59e038e14f96e69a (diff)
downloadsamba-8fcf1af559f2a716ebcfb8277668d6539fd432f0.tar.gz
ctdb-common: Avoid magic numbers when building TCP packets
Most packet sizes and offsets are multiples of 32-bit words. The IPv6 payload length is in octets. The IPv6 version is the top 4 bits of the relevant field. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Diffstat (limited to 'ctdb/common')
-rw-r--r--ctdb/common/system_socket.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/ctdb/common/system_socket.c b/ctdb/common/system_socket.c
index 7f08b817084..41037ce1ec6 100644
--- a/ctdb/common/system_socket.c
+++ b/ctdb/common/system_socket.c
@@ -528,7 +528,7 @@ static int tcp4_build(uint8_t *buf,
memset(ip4pkt, 0, l);
ip4pkt->ip.ip_v = 4;
- ip4pkt->ip.ip_hl = sizeof(ip4pkt->ip)/4;
+ ip4pkt->ip.ip_hl = sizeof(ip4pkt->ip)/sizeof(uint32_t);
ip4pkt->ip.ip_len = htons(sizeof(ip4pkt));
ip4pkt->ip.ip_ttl = 255;
ip4pkt->ip.ip_p = IPPROTO_TCP;
@@ -545,7 +545,7 @@ static int tcp4_build(uint8_t *buf,
if (rst) {
ip4pkt->tcp.th_flags |= TH_RST;
}
- ip4pkt->tcp.th_off = sizeof(ip4pkt->tcp)/4;
+ ip4pkt->tcp.th_off = sizeof(ip4pkt->tcp)/sizeof(uint32_t);
/* this makes it easier to spot in a sniffer */
ip4pkt->tcp.th_win = htons(1234);
ip4pkt->tcp.th_sum = ip_checksum((uint16_t *)&ip4pkt->tcp,
@@ -582,8 +582,8 @@ static int tcp6_build(uint8_t *buf,
ip6pkt = (void *)buf;
memset(ip6pkt, 0, l);
- ip6pkt->ip6.ip6_vfc = 0x60;
- ip6pkt->ip6.ip6_plen = htons(20);
+ ip6pkt->ip6.ip6_vfc = 6 << 4;
+ ip6pkt->ip6.ip6_plen = htons(sizeof(struct tcphdr));
ip6pkt->ip6.ip6_nxt = IPPROTO_TCP;
ip6pkt->ip6.ip6_hlim = 64;
ip6pkt->ip6.ip6_src = src->sin6_addr;
@@ -598,7 +598,7 @@ static int tcp6_build(uint8_t *buf,
if (rst) {
ip6pkt->tcp.th_flags |= TH_RST;
}
- ip6pkt->tcp.th_off = sizeof(ip6pkt->tcp)/4;
+ ip6pkt->tcp.th_off = sizeof(ip6pkt->tcp)/sizeof(uint32_t);
/* this makes it easier to spot in a sniffer */
ip6pkt->tcp.th_win = htons(1234);
ip6pkt->tcp.th_sum = ip6_checksum((uint16_t *)&ip6pkt->tcp,