summaryrefslogtreecommitdiff
path: root/accel-pppd/ctrl
diff options
context:
space:
mode:
authorVolodymyr Huti <volodymyr.huti@gmail.com>2022-10-13 14:20:06 +0300
committerVolodymyr Huti <volodymyr.huti@gmail.com>2022-10-22 15:11:29 +0300
commit6e5f9980a8a71015a228279e07970621d23c7b35 (patch)
tree73ae1d6596a175c76a0d24867592a4016c0592c5 /accel-pppd/ctrl
parent2b865db72bc2ddc6411950d72f1c23e8ef115b8a (diff)
downloadaccel-ppp-6e5f9980a8a71015a228279e07970621d23c7b35.tar.gz
accel-ppp-6e5f9980a8a71015a228279e07970621d23c7b35.zip
T72: Fix compilations warnings for unaligned variable access
- IPoE/DHCP4: Specify minimal suitable alignment explicitly. We need to guarantee 2 byte alignment for the `hdr` pointer in `ip_csum(uint16_t *buf)` calculation - PPPOE: Suppress false-positive warning for `sockaddr_pppox`. Similiar issue: https://github.com/kernelslacker/trinity/pull/40 - Introduce tmp variables to avoid alignment issues for SSTP/DHCPv6 For additional details: https://phabricator.accel-ppp.org/T72 Signed-off-by: Volodymyr Huti <v.huti@vyos.io>
Diffstat (limited to 'accel-pppd/ctrl')
-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
4 files changed, 23 insertions, 14 deletions
diff --git a/accel-pppd/ctrl/ipoe/dhcpv4.c b/accel-pppd/ctrl/ipoe/dhcpv4.c
index f1d9c460..41cbe50a 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);