summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEshenko Dmitriy <dmitriy.eshenko@vyos.io>2022-11-01 13:09:01 +0300
committerGitHub <noreply@github.com>2022-11-01 13:09:01 +0300
commitadfc132b96a4fbfb3a10f49e04e15c6669abf11d (patch)
tree591392669a1ff54b7bf53df4c16a0de7d7cd48a1
parentf4a22056a221d69bf8d1aaa8eca39f276b52431d (diff)
parent6e5f9980a8a71015a228279e07970621d23c7b35 (diff)
downloadaccel-ppp-adfc132b96a4fbfb3a10f49e04e15c6669abf11d.tar.gz
accel-ppp-adfc132b96a4fbfb3a10f49e04e15c6669abf11d.zip
Merge pull request #64 from volodymyrhuti/master
T72: Fix compilations warnings for unaligned variable access
-rw-r--r--accel-pppd/ctrl/ipoe/dhcpv4.c2
-rw-r--r--accel-pppd/ctrl/ipoe/dhcpv4.h1
-rw-r--r--accel-pppd/ctrl/pppoe/pppoe.c3
-rw-r--r--accel-pppd/ctrl/sstp/sstp.c31
-rw-r--r--accel-pppd/ipv6/dhcpv6.c20
5 files changed, 35 insertions, 22 deletions
diff --git a/accel-pppd/ctrl/ipoe/dhcpv4.c b/accel-pppd/ctrl/ipoe/dhcpv4.c
index a369c8a0..5218a73b 100644
--- a/accel-pppd/ctrl/ipoe/dhcpv4.c
+++ b/accel-pppd/ctrl/ipoe/dhcpv4.c
@@ -625,7 +625,7 @@ static int dhcpv4_send_raw(struct dhcpv4_serv *serv, struct dhcpv4_packet *pack,
struct iphdr ip;
struct udphdr udp;
uint8_t data[0];
- } __packed *hdr;
+ } __packed __aligned(2) *hdr;
struct sockaddr_ll ll_addr;
int n, len = pack->ptr - pack->data;
diff --git a/accel-pppd/ctrl/ipoe/dhcpv4.h b/accel-pppd/ctrl/ipoe/dhcpv4.h
index 8598b61d..796b858f 100644
--- a/accel-pppd/ctrl/ipoe/dhcpv4.h
+++ b/accel-pppd/ctrl/ipoe/dhcpv4.h
@@ -8,6 +8,7 @@
#include "triton.h"
+#define __aligned(n) __attribute__((aligned (n)))
#define __packed __attribute__((packed))
#define DHCP_SERV_PORT 67
diff --git a/accel-pppd/ctrl/pppoe/pppoe.c b/accel-pppd/ctrl/pppoe/pppoe.c
index 43163f16..44b094b0 100644
--- a/accel-pppd/ctrl/pppoe/pppoe.c
+++ b/accel-pppd/ctrl/pppoe/pppoe.c
@@ -433,6 +433,8 @@ static struct pppoe_conn_t *allocate_channel(struct pppoe_serv_t *serv, const ui
return conn;
}
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Waddress-of-packed-member"
static void connect_channel(struct pppoe_conn_t *conn)
{
int sock;
@@ -486,6 +488,7 @@ out_err_close:
out_err:
disconnect(conn);
}
+#pragma GCC diagnostic pop
static struct pppoe_conn_t *find_channel(struct pppoe_serv_t *serv, const uint8_t *cookie)
{
diff --git a/accel-pppd/ctrl/sstp/sstp.c b/accel-pppd/ctrl/sstp/sstp.c
index 40c6ad91..a97f4ec5 100644
--- a/accel-pppd/ctrl/sstp/sstp.c
+++ b/accel-pppd/ctrl/sstp/sstp.c
@@ -286,12 +286,15 @@ static int _vstrsep(char *buf, const char *sep, ...)
static in_addr_t sockaddr_ipv4(struct sockaddr_t *addr)
{
+ struct in6_addr inaddr6;
+
switch (addr->u.sa.sa_family) {
case AF_INET:
return addr->u.sin.sin_addr.s_addr;
case AF_INET6:
- if (IN6_IS_ADDR_V4MAPPED(&addr->u.sin6.sin6_addr))
- return addr->u.sin6.sin6_addr.s6_addr32[3];
+ inaddr6 = addr->u.sin6.sin6_addr;
+ if (IN6_IS_ADDR_V4MAPPED(&inaddr6))
+ return inaddr6.s6_addr32[3];
/* fall through */
default:
return INADDR_ANY;
@@ -301,22 +304,22 @@ static in_addr_t sockaddr_ipv4(struct sockaddr_t *addr)
static int sockaddr_ntop(struct sockaddr_t *addr, char *dst, socklen_t size, int flags)
{
char ipv6_buf[INET6_ADDRSTRLEN], *path, sign;
+ struct sockaddr_in6 sin6 = addr->u.sin6;
+ struct in6_addr inaddr6 = sin6.sin6_addr;
switch (addr->u.sa.sa_family) {
case AF_INET:
return snprintf(dst, size, (flags & FLAG_NOPORT) ? "%s" : "%s:%d",
inet_ntoa(addr->u.sin.sin_addr), ntohs(addr->u.sin.sin_port));
case AF_INET6:
- if (IN6_IS_ADDR_V4MAPPED(&addr->u.sin6.sin6_addr)) {
- inet_ntop(AF_INET, &addr->u.sin6.sin6_addr.s6_addr32[3],
- ipv6_buf, sizeof(ipv6_buf));
+ if (IN6_IS_ADDR_V4MAPPED(&inaddr6)) {
+ inet_ntop(AF_INET, &inaddr6.s6_addr32[3], ipv6_buf, sizeof(ipv6_buf));
return snprintf(dst, size, (flags & FLAG_NOPORT) ? "%s" : "%s:%d",
- ipv6_buf, ntohs(addr->u.sin6.sin6_port));
+ ipv6_buf, ntohs(sin6.sin6_port));
} else {
- inet_ntop(AF_INET6, &addr->u.sin6.sin6_addr,
- ipv6_buf, sizeof(ipv6_buf));
+ inet_ntop(AF_INET6, &inaddr6, ipv6_buf, sizeof(ipv6_buf));
return snprintf(dst, size, (flags & FLAG_NOPORT) ? "%s" : "[%s]:%d",
- ipv6_buf, ntohs(addr->u.sin6.sin6_port));
+ ipv6_buf, ntohs(sin6.sin6_port));
}
case AF_UNIX:
if (addr->len <= offsetof(typeof(addr->u.sun), sun_path)) {
@@ -2276,12 +2279,14 @@ static int sstp_connect(struct triton_md_handler_t *h)
struct sstp_conn_t *conn;
struct sockaddr_t addr;
char addr_buf[ADDRSTR_MAXLEN];
+ socklen_t addrlen;
in_addr_t ip;
int sock, value;
while (1) {
- addr.len = sizeof(addr.u);
- sock = accept(h->fd, &addr.u.sa, &addr.len);
+ addrlen = sizeof(addr.u);
+ sock = accept(h->fd, &addr.u.sa, &addrlen);
+ addr.len = addrlen;
if (sock < 0) {
if (errno == EAGAIN)
return 0;
@@ -2408,8 +2413,8 @@ static int sstp_connect(struct triton_md_handler_t *h)
sockaddr_ntop(&addr, addr_buf, sizeof(addr_buf), FLAG_NOPORT);
conn->ctrl.calling_station_id = _strdup(addr_buf);
- addr.len = sizeof(addr.u);
- getsockname(sock, &addr.u.sa, &addr.len);
+ addrlen = sizeof(addr.u);
+ getsockname(sock, &addr.u.sa, &addrlen);
sockaddr_ntop(&addr, addr_buf, sizeof(addr_buf), FLAG_NOPORT);
conn->ctrl.called_station_id = _strdup(addr_buf);
diff --git a/accel-pppd/ipv6/dhcpv6.c b/accel-pppd/ipv6/dhcpv6.c
index cefbcfd8..158771b1 100644
--- a/accel-pppd/ipv6/dhcpv6.c
+++ b/accel-pppd/ipv6/dhcpv6.c
@@ -244,8 +244,8 @@ static void dhcpv6_send_reply(struct dhcpv6_packet *req, struct dhcpv6_pd *pd, i
struct dhcpv6_opt_ia_na *ia_na;
struct dhcpv6_opt_ia_addr *ia_addr;
struct dhcpv6_opt_ia_prefix *ia_prefix;
+ struct in6_addr addr, prefix;
struct ipv6db_addr_t *a;
- struct in6_addr addr;
struct ap_session *ses = req->ses;
int f = 0, f1, f2 = 0;
@@ -282,7 +282,8 @@ static void dhcpv6_send_reply(struct dhcpv6_packet *req, struct dhcpv6_pd *pd, i
opt2 = dhcpv6_nested_option_alloc(reply, opt1, D6_OPTION_IAADDR, sizeof(*ia_addr) - sizeof(struct dhcpv6_opt_hdr));
ia_addr = (struct dhcpv6_opt_ia_addr *)opt2->hdr;
- build_ip6_addr(a, ses->ipv6->peer_intf_id, &ia_addr->addr);
+ build_ip6_addr(a, ses->ipv6->peer_intf_id, &addr);
+ memcpy(&ia_addr->addr, &addr, sizeof(addr));
ia_addr->pref_lifetime = htonl(conf_pref_lifetime);
ia_addr->valid_lifetime = htonl(conf_valid_lifetime);
@@ -309,8 +310,9 @@ static void dhcpv6_send_reply(struct dhcpv6_packet *req, struct dhcpv6_pd *pd, i
list_for_each_entry(opt2, &opt->opt_list, entry) {
if (ntohs(opt2->hdr->code) == D6_OPTION_IAADDR) {
ia_addr = (struct dhcpv6_opt_ia_addr *)opt2->hdr;
+ addr = ia_addr->addr;
- if (IN6_IS_ADDR_UNSPECIFIED(&ia_addr->addr))
+ if (IN6_IS_ADDR_UNSPECIFIED(&addr))
continue;
f1 = 0;
@@ -389,8 +391,9 @@ static void dhcpv6_send_reply(struct dhcpv6_packet *req, struct dhcpv6_pd *pd, i
list_for_each_entry(opt2, &opt->opt_list, entry) {
if (ntohs(opt2->hdr->code) == D6_OPTION_IAPREFIX) {
ia_prefix = (struct dhcpv6_opt_ia_prefix *)opt2->hdr;
+ prefix = ia_prefix->prefix;
- if (ia_prefix->prefix_len == 0 || IN6_IS_ADDR_UNSPECIFIED(&ia_prefix->prefix))
+ if (ia_prefix->prefix_len == 0 || IN6_IS_ADDR_UNSPECIFIED(&prefix))
continue;
f1 = 0;
@@ -464,7 +467,7 @@ static void dhcpv6_send_reply2(struct dhcpv6_packet *req, struct dhcpv6_pd *pd,
struct dhcpv6_opt_ia_addr *ia_addr;
struct dhcpv6_opt_ia_prefix *ia_prefix;
struct ipv6db_addr_t *a;
- struct in6_addr addr;
+ struct in6_addr addr, prefix;
struct ap_session *ses = req->ses;
int f = 0, f1, f2 = 0, f3;
@@ -488,8 +491,8 @@ static void dhcpv6_send_reply2(struct dhcpv6_packet *req, struct dhcpv6_pd *pd,
list_for_each_entry(opt2, &opt->opt_list, entry) {
if (ntohs(opt2->hdr->code) == D6_OPTION_IAADDR) {
ia_addr = (struct dhcpv6_opt_ia_addr *)opt2->hdr;
-
- if (IN6_IS_ADDR_UNSPECIFIED(&ia_addr->addr))
+ addr = ia_addr->addr;
+ if (IN6_IS_ADDR_UNSPECIFIED(&addr))
continue;
f1 = 0;
@@ -550,8 +553,9 @@ static void dhcpv6_send_reply2(struct dhcpv6_packet *req, struct dhcpv6_pd *pd,
list_for_each_entry(opt2, &opt->opt_list, entry) {
if (ntohs(opt2->hdr->code) == D6_OPTION_IAPREFIX) {
ia_prefix = (struct dhcpv6_opt_ia_prefix *)opt2->hdr;
+ prefix = ia_prefix->prefix;
- if (ia_prefix->prefix_len == 0 || IN6_IS_ADDR_UNSPECIFIED(&ia_prefix->prefix))
+ if (ia_prefix->prefix_len == 0 || IN6_IS_ADDR_UNSPECIFIED(&prefix))
continue;
f1 = 0;