aboutgitcodebugslistschat
diff options
context:
space:
mode:
-rw-r--r--conf.c6
-rw-r--r--dhcpv6.c33
-rw-r--r--tcp.c37
-rw-r--r--udp.c15
4 files changed, 53 insertions, 38 deletions
diff --git a/conf.c b/conf.c
index 8e96368..d7ddfd7 100644
--- a/conf.c
+++ b/conf.c
@@ -323,7 +323,9 @@ static void get_dns(struct ctx *c)
if (end)
*end = 0;
- p = strtok(buf, " \t");
+ if (!strtok(buf, " \t"))
+ continue;
+
while (s - c->dns_search < ARRAY_SIZE(c->dns_search) - 1
&& (p = strtok(NULL, " \t"))) {
strncpy(s->n, p, sizeof(c->dns_search[0]));
@@ -371,7 +373,7 @@ static int conf_ns_opt(struct ctx *c,
char *nsdir, char *conf_userns, const char *optarg)
{
int ufd = 0, nfd = 0, try, ret, netns_only_reset = c->netns_only;
- char userns[PATH_MAX], netns[PATH_MAX];
+ char userns[PATH_MAX] = { 0 }, netns[PATH_MAX];
char *endptr;
pid_t pid;
diff --git a/dhcpv6.c b/dhcpv6.c
index d514e8d..cac220e 100644
--- a/dhcpv6.c
+++ b/dhcpv6.c
@@ -99,15 +99,19 @@ struct opt_server_id {
uint8_t duid_lladdr[ETH_ALEN];
};
-static const struct opt_server_id server_id_const = {
- { OPT_SERVERID, OPT_SIZE(server_id) },
#if __BYTE_ORDER == __BIG_ENDIAN
- DUID_TYPE_LLT, ARPHRD_ETHER,
+#define SERVER_ID { \
+ { OPT_SERVERID, OPT_SIZE(server_id) }, \
+ DUID_TYPE_LLT, ARPHRD_ETHER, 0, { 0 } \
+}
#else
- __bswap_constant_16(DUID_TYPE_LLT), __bswap_constant_16(ARPHRD_ETHER),
+#define SERVER_ID { \
+ { OPT_SERVERID, OPT_SIZE(server_id) }, \
+ __bswap_constant_16(DUID_TYPE_LLT), \
+ __bswap_constant_16(ARPHRD_ETHER), \
+ 0, { 0 } \
+}
#endif
- 0, { 0 }
-};
/**
* struct opt_ia_na - Identity Association for Non-temporary Addresses Option
@@ -200,13 +204,11 @@ struct msg_hdr {
uint32_t xid:24;
} __attribute__((__packed__));
-static const struct udphdr uh_resp = {
#if __BYTE_ORDER == __BIG_ENDIAN
- 547, 546, 0, 0,
+#define UH_RESP { 547, 546, 0, 0, }
#else
- __bswap_constant_16(547), __bswap_constant_16(546), 0, 0,
+#define UH_RESP { __bswap_constant_16(547), __bswap_constant_16(546), 0, 0 }
#endif
-};
/**
* struct resp_t - Normal advertise and reply message
@@ -230,9 +232,9 @@ static struct resp_t {
struct opt_dns_servers dns_servers;
struct opt_dns_search dns_search;
} __attribute__((__packed__)) resp = {
- uh_resp,
+ UH_RESP,
{ 0 },
- server_id_const,
+ SERVER_ID,
{ { OPT_IA_NA, OPT_SIZE_CONV(sizeof(struct opt_ia_na) +
sizeof(struct opt_ia_addr) -
@@ -278,9 +280,9 @@ static struct resp_not_on_link_t {
uint8_t var[sizeof(struct opt_ia_na) + sizeof(struct opt_status_code) +
sizeof(struct opt_client_id)];
} __attribute__((__packed__)) resp_not_on_link = {
- uh_resp,
+ UH_RESP,
{ TYPE_REPLY, 0 },
- server_id_const,
+ SERVER_ID,
{ 0, },
};
@@ -390,6 +392,7 @@ static size_t dhcpv6_dns_fill(struct ctx *c, char *buf, int offset)
{
struct opt_dns_servers *srv = NULL;
struct opt_dns_search *srch = NULL;
+ char *p = NULL;
int i;
for (i = 0; !IN6_IS_ADDR_UNSPECIFIED(&c->dns6[i]); i++) {
@@ -409,8 +412,6 @@ static size_t dhcpv6_dns_fill(struct ctx *c, char *buf, int offset)
srv->hdr.l = htons(srv->hdr.l);
for (i = 0; *c->dns_search[i].n; i++) {
- char *p;
-
if (!i) {
srch = (struct opt_dns_search *)(buf + offset);
offset += sizeof(struct opt_hdr);
diff --git a/tcp.c b/tcp.c
index 99674ef..de28891 100644
--- a/tcp.c
+++ b/tcp.c
@@ -2910,48 +2910,53 @@ static void tcp_conn_from_sock(struct ctx *c, union epoll_ref ref,
ref_conn.s = conn->sock = s;
if (ref.tcp.v6) {
- struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)&sa;
+ struct sockaddr_in6 sa6;
- if (IN6_IS_ADDR_LOOPBACK(&sa6->sin6_addr) ||
- !memcmp(&sa6->sin6_addr, &c->addr6_seen, sizeof(c->gw6)) ||
- !memcmp(&sa6->sin6_addr, &c->addr6, sizeof(c->gw6)))
- memcpy(&sa6->sin6_addr, &c->gw6, sizeof(c->gw6));
+ memcpy(&sa6, &sa, sizeof(sa6));
- memcpy(&conn->a.a6, &sa6->sin6_addr, sizeof(conn->a.a6));
+ if (IN6_IS_ADDR_LOOPBACK(&sa6.sin6_addr) ||
+ !memcmp(&sa6.sin6_addr, &c->addr6_seen, sizeof(c->gw6)) ||
+ !memcmp(&sa6.sin6_addr, &c->addr6, sizeof(c->gw6)))
+ memcpy(&sa6.sin6_addr, &c->gw6, sizeof(c->gw6));
- conn->sock_port = ntohs(sa6->sin6_port);
+ memcpy(&conn->a.a6, &sa6.sin6_addr, sizeof(conn->a.a6));
+
+ conn->sock_port = ntohs(sa6.sin6_port);
conn->tap_port = ref.tcp.index;
- conn->seq_to_tap = tcp_seq_init(c, AF_INET6, &sa6->sin6_addr,
+ conn->seq_to_tap = tcp_seq_init(c, AF_INET6, &sa6.sin6_addr,
conn->sock_port,
conn->tap_port,
now);
conn->seq_init_to_tap = conn->seq_to_tap;
- tcp_hash_insert(c, conn, AF_INET6, &sa6->sin6_addr);
+ tcp_hash_insert(c, conn, AF_INET6, &sa6.sin6_addr);
} else {
- struct sockaddr_in *sa4 = (struct sockaddr_in *)&sa;
- in_addr_t s_addr = ntohl(sa4->sin_addr.s_addr);
+ struct sockaddr_in sa4;
+ in_addr_t s_addr;
+
+ memcpy(&sa4, &sa, sizeof(sa4));
+ s_addr = sa4.sin_addr.s_addr;
memset(&conn->a.a4.zero, 0, sizeof(conn->a.a4.zero));
memset(&conn->a.a4.one, 0xff, sizeof(conn->a.a4.one));
if (s_addr >> IN_CLASSA_NSHIFT == IN_LOOPBACKNET ||
s_addr == INADDR_ANY || s_addr == htonl(c->addr4_seen))
- sa4->sin_addr.s_addr = c->gw4;
+ sa4.sin_addr.s_addr = c->gw4;
- memcpy(&conn->a.a4.a, &sa4->sin_addr, sizeof(conn->a.a4.a));
+ memcpy(&conn->a.a4.a, &s_addr, sizeof(conn->a.a4.a));
- conn->sock_port = ntohs(sa4->sin_port);
+ conn->sock_port = ntohs(sa4.sin_port);
conn->tap_port = ref.tcp.index;
- conn->seq_to_tap = tcp_seq_init(c, AF_INET, &sa4->sin_addr,
+ conn->seq_to_tap = tcp_seq_init(c, AF_INET, &s_addr,
conn->sock_port,
conn->tap_port,
now);
conn->seq_init_to_tap = conn->seq_to_tap;
- tcp_hash_insert(c, conn, AF_INET, &sa4->sin_addr);
+ tcp_hash_insert(c, conn, AF_INET, &s_addr);
}
conn->seq_ack_from_tap = conn->seq_to_tap + 1;
diff --git a/udp.c b/udp.c
index 5c0e955..0703fc9 100644
--- a/udp.c
+++ b/udp.c
@@ -461,10 +461,17 @@ int udp_splice_connect(struct ctx *c, int v6, int bound_sock,
if (getsockname(s, (struct sockaddr *)&sa, &sl))
goto fail;
- if (v6)
- ref.udp.port = ntohs(((struct sockaddr_in6 *)&sa)->sin6_port);
- else
- ref.udp.port = ntohs(((struct sockaddr_in *)&sa)->sin_port);
+ if (v6) {
+ struct sockaddr_in6 sa6;
+
+ memcpy(&sa6, &sa, sizeof(sa6));
+ ref.udp.port = ntohs(sa6.sin6_port);
+ } else {
+ struct sockaddr_in sa4;
+
+ memcpy(&sa4, &sa, sizeof(sa4));
+ ref.udp.port = ntohs(sa4.sin_port);
+ }
sp = &udp_splice_map[v6 ? V6 : V4][ref.udp.port];
if (splice == UDP_BACK_TO_INIT) {