udp: Avoid unnecessary pointer in udp_update_hdr4()
We carry around the source address as a pointer to a constant struct in_addr. But it's silly to carry around a 4 or 8 byte pointer to a 4 byte IPv4 address. Just copy the IPv4 address around by value. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
parent
b0419d150a
commit
ae69838db0
1 changed files with 9 additions and 9 deletions
18
udp.c
18
udp.c
|
@ -575,32 +575,32 @@ static size_t udp_update_hdr4(const struct ctx *c, struct udp4_l2_buf_t *b,
|
||||||
const struct timespec *now)
|
const struct timespec *now)
|
||||||
{
|
{
|
||||||
size_t ip_len = datalen + sizeof(b->iph) + sizeof(b->uh);
|
size_t ip_len = datalen + sizeof(b->iph) + sizeof(b->uh);
|
||||||
const struct in_addr *src = &b->s_in.sin_addr;
|
|
||||||
in_port_t srcport = ntohs(b->s_in.sin_port);
|
in_port_t srcport = ntohs(b->s_in.sin_port);
|
||||||
|
struct in_addr src = b->s_in.sin_addr;
|
||||||
|
|
||||||
if (!IN4_IS_ADDR_UNSPECIFIED(&c->ip4.dns_match) &&
|
if (!IN4_IS_ADDR_UNSPECIFIED(&c->ip4.dns_match) &&
|
||||||
IN4_ARE_ADDR_EQUAL(src, &c->ip4.dns_host) && srcport == 53) {
|
IN4_ARE_ADDR_EQUAL(&src, &c->ip4.dns_host) && srcport == 53) {
|
||||||
src = &c->ip4.dns_match;
|
src = c->ip4.dns_match;
|
||||||
} else if (IN4_IS_ADDR_LOOPBACK(src) ||
|
} else if (IN4_IS_ADDR_LOOPBACK(&src) ||
|
||||||
IN4_ARE_ADDR_EQUAL(src, &c->ip4.addr_seen)) {
|
IN4_ARE_ADDR_EQUAL(&src, &c->ip4.addr_seen)) {
|
||||||
udp_tap_map[V4][srcport].ts = now->tv_sec;
|
udp_tap_map[V4][srcport].ts = now->tv_sec;
|
||||||
udp_tap_map[V4][srcport].flags |= PORT_LOCAL;
|
udp_tap_map[V4][srcport].flags |= PORT_LOCAL;
|
||||||
|
|
||||||
if (IN4_IS_ADDR_LOOPBACK(src))
|
if (IN4_IS_ADDR_LOOPBACK(&src))
|
||||||
udp_tap_map[V4][srcport].flags |= PORT_LOOPBACK;
|
udp_tap_map[V4][srcport].flags |= PORT_LOOPBACK;
|
||||||
else
|
else
|
||||||
udp_tap_map[V4][srcport].flags &= ~PORT_LOOPBACK;
|
udp_tap_map[V4][srcport].flags &= ~PORT_LOOPBACK;
|
||||||
|
|
||||||
bitmap_set(udp_act[V4][UDP_ACT_TAP], srcport);
|
bitmap_set(udp_act[V4][UDP_ACT_TAP], srcport);
|
||||||
|
|
||||||
src = &c->ip4.gw;
|
src = c->ip4.gw;
|
||||||
}
|
}
|
||||||
|
|
||||||
b->iph.tot_len = htons(ip_len);
|
b->iph.tot_len = htons(ip_len);
|
||||||
b->iph.daddr = c->ip4.addr_seen.s_addr;
|
b->iph.daddr = c->ip4.addr_seen.s_addr;
|
||||||
b->iph.saddr = src->s_addr;
|
b->iph.saddr = src.s_addr;
|
||||||
b->iph.check = csum_ip4_header(b->iph.tot_len, IPPROTO_UDP,
|
b->iph.check = csum_ip4_header(b->iph.tot_len, IPPROTO_UDP,
|
||||||
*src, c->ip4.addr_seen);
|
src, c->ip4.addr_seen);
|
||||||
|
|
||||||
b->uh.source = b->s_in.sin_port;
|
b->uh.source = b->s_in.sin_port;
|
||||||
b->uh.dest = htons(dstport);
|
b->uh.dest = htons(dstport);
|
||||||
|
|
Loading…
Reference in a new issue