From owner-dev-commits-src-main@freebsd.org Tue Jan 19 21:38:15 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id EC95C4E0891; Tue, 19 Jan 2021 21:38:15 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DL28760dVz4lMh; Tue, 19 Jan 2021 21:38:15 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id C0C935DE3; Tue, 19 Jan 2021 21:38:15 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 10JLcFxO078411; Tue, 19 Jan 2021 21:38:15 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 10JLcFIt078410; Tue, 19 Jan 2021 21:38:15 GMT (envelope-from git) Date: Tue, 19 Jan 2021 21:38:15 GMT Message-Id: <202101192138.10JLcFIt078410@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Alex Richardson Subject: git: bc596e563245 - main - libalias: Fix -Wcast-align compiler warnings MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: arichardson X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: bc596e563245d838a27e3c7aaf090caa49af1016 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Jan 2021 21:38:16 -0000 The branch main has been updated by arichardson: URL: https://cgit.FreeBSD.org/src/commit/?id=bc596e563245d838a27e3c7aaf090caa49af1016 commit bc596e563245d838a27e3c7aaf090caa49af1016 Author: Alex Richardson AuthorDate: 2021-01-19 11:32:32 +0000 Commit: Alex Richardson CommitDate: 2021-01-19 21:23:24 +0000 libalias: Fix -Wcast-align compiler warnings This fixes -Wcast-align warnings caused by the underaligned `struct ip`. This also silences them in the public functions by changing the function signature from char * to void *. This is source and binary compatible and avoids the -Wcast-align warning. Reviewed By: ae, gbe (manpages) Differential Revision: https://reviews.freebsd.org/D27882 --- sys/netinet/libalias/alias.c | 102 ++++++++++++++++++------------------- sys/netinet/libalias/alias.h | 14 ++--- sys/netinet/libalias/alias_db.c | 4 +- sys/netinet/libalias/alias_local.h | 4 +- sys/netinet/libalias/alias_proxy.c | 2 +- sys/netinet/libalias/libalias.3 | 16 +++--- 6 files changed, 69 insertions(+), 73 deletions(-) diff --git a/sys/netinet/libalias/alias.c b/sys/netinet/libalias/alias.c index 267bd2118222..8d5097943080 100644 --- a/sys/netinet/libalias/alias.c +++ b/sys/netinet/libalias/alias.c @@ -274,9 +274,9 @@ static int IcmpAliasOut2(struct libalias *, struct ip *); static int IcmpAliasOut(struct libalias *, struct ip *, int create); static int ProtoAliasIn(struct libalias *la, struct in_addr ip_src, - struct in_addr *ip_dst, u_char ip_p, u_short *ip_sum); -static int ProtoAliasOut(struct libalias *la, struct in_addr *ip_src, - struct in_addr ip_dst, u_char ip_p, u_short *ip_sum, + struct ip *pip, u_char ip_p, u_short *ip_sum); +static int ProtoAliasOut(struct libalias *la, struct ip *pip, + struct in_addr ip_dst, u_char ip_p, u_short *ip_sum, int create); static int UdpAliasIn(struct libalias *, struct ip *); @@ -655,8 +655,8 @@ IcmpAliasOut(struct libalias *la, struct ip *pip, int create) } static int -ProtoAliasIn(struct libalias *la, struct in_addr ip_src, - struct in_addr *ip_dst, u_char ip_p, u_short *ip_sum) +ProtoAliasIn(struct libalias *la, struct in_addr ip_src, + struct ip *pip, u_char ip_p, u_short *ip_sum) { /* Handle incoming IP packets. The @@ -671,7 +671,7 @@ ProtoAliasIn(struct libalias *la, struct in_addr ip_src, if (la->packetAliasMode & PKT_ALIAS_PROXY_ONLY) return (PKT_ALIAS_OK); - lnk = FindProtoIn(la, ip_src, *ip_dst, ip_p); + lnk = FindProtoIn(la, ip_src, pip->ip_dst, ip_p); if (lnk != NULL) { struct in_addr original_address; @@ -679,8 +679,8 @@ ProtoAliasIn(struct libalias *la, struct in_addr ip_src, /* Restore original IP address */ DifferentialChecksum(ip_sum, - &original_address, ip_dst, 2); - *ip_dst = original_address; + &original_address, &pip->ip_dst, 2); + pip->ip_dst = original_address; return (PKT_ALIAS_OK); } @@ -688,7 +688,7 @@ ProtoAliasIn(struct libalias *la, struct in_addr ip_src, } static int -ProtoAliasOut(struct libalias *la, struct in_addr *ip_src, +ProtoAliasOut(struct libalias *la, struct ip *pip, struct in_addr ip_dst, u_char ip_p, u_short *ip_sum, int create) { /* @@ -707,7 +707,7 @@ ProtoAliasOut(struct libalias *la, struct in_addr *ip_src, if (!create) return (PKT_ALIAS_IGNORED); - lnk = FindProtoOut(la, *ip_src, ip_dst, ip_p); + lnk = FindProtoOut(la, pip->ip_src, ip_dst, ip_p); if (lnk != NULL) { struct in_addr alias_address; @@ -715,8 +715,8 @@ ProtoAliasOut(struct libalias *la, struct in_addr *ip_src, /* Change source address */ DifferentialChecksum(ip_sum, - &alias_address, ip_src, 2); - *ip_src = alias_address; + &alias_address, &pip->ip_src, 2); + pip->ip_src = alias_address; return (PKT_ALIAS_OK); } @@ -1185,26 +1185,26 @@ saved and recalled when a header fragment is seen. */ /* Local prototypes */ -static int FragmentIn(struct libalias *la, struct in_addr ip_src, - struct in_addr *ip_dst, u_short ip_id, u_short *ip_sum); -static int FragmentOut(struct libalias *, struct in_addr *ip_src, +static int FragmentIn(struct libalias *la, struct in_addr ip_src, + struct ip *pip, u_short ip_id, u_short *ip_sum); +static int FragmentOut(struct libalias *, struct ip *pip, u_short *ip_sum); static int -FragmentIn(struct libalias *la, struct in_addr ip_src, struct in_addr *ip_dst, +FragmentIn(struct libalias *la, struct in_addr ip_src, struct ip *pip, u_short ip_id, u_short *ip_sum) { struct alias_link *lnk; LIBALIAS_LOCK_ASSERT(la); - lnk = FindFragmentIn2(la, ip_src, *ip_dst, ip_id); + lnk = FindFragmentIn2(la, ip_src, pip->ip_dst, ip_id); if (lnk != NULL) { struct in_addr original_address; GetFragmentAddr(lnk, &original_address); DifferentialChecksum(ip_sum, - &original_address, ip_dst, 2); - *ip_dst = original_address; + &original_address, &pip->ip_dst, 2); + pip->ip_dst = original_address; return (PKT_ALIAS_OK); } @@ -1212,15 +1212,15 @@ FragmentIn(struct libalias *la, struct in_addr ip_src, struct in_addr *ip_dst, } static int -FragmentOut(struct libalias *la, struct in_addr *ip_src, u_short *ip_sum) +FragmentOut(struct libalias *la, struct ip *pip, u_short *ip_sum) { struct in_addr alias_address; LIBALIAS_LOCK_ASSERT(la); - alias_address = FindAliasAddress(la, *ip_src); + alias_address = FindAliasAddress(la, pip->ip_src); DifferentialChecksum(ip_sum, - &alias_address, ip_src, 2); - *ip_src = alias_address; + &alias_address, &pip->ip_src, 2); + pip->ip_src = alias_address; return (PKT_ALIAS_OK); } @@ -1238,7 +1238,7 @@ FragmentOut(struct libalias *la, struct in_addr *ip_src, u_short *ip_sum) */ int -LibAliasSaveFragment(struct libalias *la, char *ptr) +LibAliasSaveFragment(struct libalias *la, void *ptr) { int iresult; struct alias_link *lnk; @@ -1256,11 +1256,11 @@ LibAliasSaveFragment(struct libalias *la, char *ptr) return (iresult); } -char * -LibAliasGetFragment(struct libalias *la, char *ptr) +void * +LibAliasGetFragment(struct libalias *la, void *ptr) { struct alias_link *lnk; - char *fptr; + void *fptr; struct ip *pip; LIBALIAS_LOCK(la); @@ -1278,10 +1278,10 @@ LibAliasGetFragment(struct libalias *la, char *ptr) } void -LibAliasFragmentIn(struct libalias *la, char *ptr, /* Points to correctly +LibAliasFragmentIn(struct libalias *la, void *ptr, /* Points to correctly * de-aliased header * fragment */ - char *ptr_fragment /* Points to fragment which must be + void *ptr_fragment /* Points to fragment which must be * de-aliased */ ) { @@ -1301,39 +1301,37 @@ LibAliasFragmentIn(struct libalias *la, char *ptr, /* Points to correctly /* Local prototypes */ static int -LibAliasOutLocked(struct libalias *la, char *ptr, +LibAliasOutLocked(struct libalias *la, struct ip *pip, int maxpacketsize, int create); static int -LibAliasInLocked(struct libalias *la, char *ptr, +LibAliasInLocked(struct libalias *la, struct ip *pip, int maxpacketsize); int -LibAliasIn(struct libalias *la, char *ptr, int maxpacketsize) +LibAliasIn(struct libalias *la, void *ptr, int maxpacketsize) { int res; LIBALIAS_LOCK(la); - res = LibAliasInLocked(la, ptr, maxpacketsize); + res = LibAliasInLocked(la, (struct ip *)ptr, maxpacketsize); LIBALIAS_UNLOCK(la); return (res); } static int -LibAliasInLocked(struct libalias *la, char *ptr, int maxpacketsize) +LibAliasInLocked(struct libalias *la, struct ip *pip, int maxpacketsize) { struct in_addr alias_addr; - struct ip *pip; int iresult; if (la->packetAliasMode & PKT_ALIAS_REVERSE) { la->packetAliasMode &= ~PKT_ALIAS_REVERSE; - iresult = LibAliasOutLocked(la, ptr, maxpacketsize, 1); + iresult = LibAliasOutLocked(la, pip, maxpacketsize, 1); la->packetAliasMode |= PKT_ALIAS_REVERSE; goto getout; } HouseKeeping(la); ClearCheckNewLink(la); - pip = (struct ip *)ptr; alias_addr = pip->ip_dst; /* Defense against mangled packets */ @@ -1377,12 +1375,12 @@ LibAliasInLocked(struct libalias *la, char *ptr, int maxpacketsize) if (error == 0) iresult = PKT_ALIAS_OK; else - iresult = ProtoAliasIn(la, pip->ip_src, - &pip->ip_dst, pip->ip_p, &pip->ip_sum); + iresult = ProtoAliasIn(la, pip->ip_src, + pip, pip->ip_p, &pip->ip_sum); } break; default: - iresult = ProtoAliasIn(la, pip->ip_src, &pip->ip_dst, + iresult = ProtoAliasIn(la, pip->ip_src, pip, pip->ip_p, &pip->ip_sum); break; } @@ -1399,7 +1397,7 @@ LibAliasInLocked(struct libalias *la, char *ptr, int maxpacketsize) } } } else { - iresult = FragmentIn(la, pip->ip_src, &pip->ip_dst, pip->ip_id, + iresult = FragmentIn(la, pip->ip_src, pip, pip->ip_id, &pip->ip_sum); } @@ -1426,29 +1424,29 @@ getout: #define UNREG_ADDR_CGN_UPPER 0x647fffff int -LibAliasOut(struct libalias *la, char *ptr, int maxpacketsize) +LibAliasOut(struct libalias *la, void *ptr, int maxpacketsize) { int res; LIBALIAS_LOCK(la); - res = LibAliasOutLocked(la, ptr, maxpacketsize, 1); + res = LibAliasOutLocked(la, (struct ip *)ptr, maxpacketsize, 1); LIBALIAS_UNLOCK(la); return (res); } int -LibAliasOutTry(struct libalias *la, char *ptr, int maxpacketsize, int create) +LibAliasOutTry(struct libalias *la, void *ptr, int maxpacketsize, int create) { int res; LIBALIAS_LOCK(la); - res = LibAliasOutLocked(la, ptr, maxpacketsize, create); + res = LibAliasOutLocked(la, (struct ip *)ptr, maxpacketsize, create); LIBALIAS_UNLOCK(la); return (res); } static int -LibAliasOutLocked(struct libalias *la, char *ptr, /* valid IP packet */ +LibAliasOutLocked(struct libalias *la, struct ip *pip, /* valid IP packet */ int maxpacketsize, /* How much the packet data may grow (FTP * and IRC inline changes) */ int create /* Create new entries ? */ @@ -1456,17 +1454,15 @@ LibAliasOutLocked(struct libalias *la, char *ptr, /* valid IP packet */ { int iresult; struct in_addr addr_save; - struct ip *pip; if (la->packetAliasMode & PKT_ALIAS_REVERSE) { la->packetAliasMode &= ~PKT_ALIAS_REVERSE; - iresult = LibAliasInLocked(la, ptr, maxpacketsize); + iresult = LibAliasInLocked(la, pip, maxpacketsize); la->packetAliasMode |= PKT_ALIAS_REVERSE; goto getout; } HouseKeeping(la); ClearCheckNewLink(la); - pip = (struct ip *)ptr; /* Defense against mangled packets */ if (ntohs(pip->ip_len) > maxpacketsize @@ -1532,17 +1528,17 @@ LibAliasOutLocked(struct libalias *la, char *ptr, /* valid IP packet */ if (error == 0) iresult = PKT_ALIAS_OK; else - iresult = ProtoAliasOut(la, &pip->ip_src, + iresult = ProtoAliasOut(la, pip, pip->ip_dst, pip->ip_p, &pip->ip_sum, create); } break; default: - iresult = ProtoAliasOut(la, &pip->ip_src, + iresult = ProtoAliasOut(la, pip, pip->ip_dst, pip->ip_p, &pip->ip_sum, create); break; } } else { - iresult = FragmentOut(la, &pip->ip_src, &pip->ip_sum); + iresult = FragmentOut(la, pip, &pip->ip_sum); } SetDefaultAliasAddress(la, addr_save); @@ -1551,7 +1547,7 @@ getout: } int -LibAliasUnaliasOut(struct libalias *la, char *ptr, /* valid IP packet */ +LibAliasUnaliasOut(struct libalias *la, void *ptr, /* valid IP packet */ int maxpacketsize /* for error checking */ ) { diff --git a/sys/netinet/libalias/alias.h b/sys/netinet/libalias/alias.h index a9935f7aa812..671241212799 100644 --- a/sys/netinet/libalias/alias.h +++ b/sys/netinet/libalias/alias.h @@ -93,10 +93,10 @@ unsigned int void LibAliasUninit(struct libalias *); /* Packet Handling functions. */ -int LibAliasIn (struct libalias *, char *_ptr, int _maxpacketsize); -int LibAliasOut(struct libalias *, char *_ptr, int _maxpacketsize); -int LibAliasOutTry(struct libalias *, char *_ptr, int _maxpacketsize, int _create); -int LibAliasUnaliasOut(struct libalias *, char *_ptr, int _maxpacketsize); +int LibAliasIn (struct libalias *, void *_ptr, int _maxpacketsize); +int LibAliasOut(struct libalias *, void *_ptr, int _maxpacketsize); +int LibAliasOutTry(struct libalias *, void *_ptr, int _maxpacketsize, int _create); +int LibAliasUnaliasOut(struct libalias *, void *_ptr, int _maxpacketsize); /* Port and address redirection functions. */ @@ -119,9 +119,9 @@ LibAliasRedirectProto(struct libalias *, struct in_addr _src_addr, unsigned char _proto); /* Fragment Handling functions. */ -void LibAliasFragmentIn(struct libalias *, char *_ptr, char *_ptr_fragment); -char *LibAliasGetFragment(struct libalias *, char *_ptr); -int LibAliasSaveFragment(struct libalias *, char *_ptr); +void LibAliasFragmentIn(struct libalias *, void *_ptr, void *_ptr_fragment); +void *LibAliasGetFragment(struct libalias *, void *_ptr); +int LibAliasSaveFragment(struct libalias *, void *_ptr); /* Miscellaneous functions. */ int LibAliasCheckNewLink(struct libalias *); diff --git a/sys/netinet/libalias/alias_db.c b/sys/netinet/libalias/alias_db.c index e05cc3da948f..8da9a7fe683a 100644 --- a/sys/netinet/libalias/alias_db.c +++ b/sys/netinet/libalias/alias_db.c @@ -1742,13 +1742,13 @@ GetFragmentAddr(struct alias_link *lnk, struct in_addr *src_addr) } void -SetFragmentPtr(struct alias_link *lnk, char *fptr) +SetFragmentPtr(struct alias_link *lnk, void *fptr) { lnk->data.frag_ptr = fptr; } void -GetFragmentPtr(struct alias_link *lnk, char **fptr) +GetFragmentPtr(struct alias_link *lnk, void **fptr) { *fptr = lnk->data.frag_ptr; } diff --git a/sys/netinet/libalias/alias_local.h b/sys/netinet/libalias/alias_local.h index ff6c16f7d9eb..5919851a4019 100644 --- a/sys/netinet/libalias/alias_local.h +++ b/sys/netinet/libalias/alias_local.h @@ -322,8 +322,8 @@ FindNewPortGroup(struct libalias *la, struct in_addr _dst_addr, struct in_addr _ u_char _proto, u_char _align); void GetFragmentAddr(struct alias_link *_lnk, struct in_addr *_src_addr); void SetFragmentAddr(struct alias_link *_lnk, struct in_addr _src_addr); -void GetFragmentPtr(struct alias_link *_lnk, char **_fptr); -void SetFragmentPtr(struct alias_link *_lnk, char *fptr); +void GetFragmentPtr(struct alias_link *_lnk, void **_fptr); +void SetFragmentPtr(struct alias_link *_lnk, void *fptr); void SetStateIn(struct alias_link *_lnk, int _state); void SetStateOut(struct alias_link *_lnk, int _state); int GetStateIn (struct alias_link *_lnk); diff --git a/sys/netinet/libalias/alias_proxy.c b/sys/netinet/libalias/alias_proxy.c index fc8e148d62d0..79d9db82914c 100644 --- a/sys/netinet/libalias/alias_proxy.c +++ b/sys/netinet/libalias/alias_proxy.c @@ -382,7 +382,7 @@ ProxyEncodeIpHeader(struct ip *pip, #define OPTION_LEN_BYTES 8 #define OPTION_LEN_INT16 4 #define OPTION_LEN_INT32 2 - u_char option[OPTION_LEN_BYTES]; + _Alignas(_Alignof(u_short)) u_char option[OPTION_LEN_BYTES]; #ifdef LIBALIAS_DEBUG fprintf(stdout, " ip cksum 1 = %x\n", (u_int) IpChecksum(pip)); diff --git a/sys/netinet/libalias/libalias.3 b/sys/netinet/libalias/libalias.3 index c323edf4c499..beef2ff7fca5 100644 --- a/sys/netinet/libalias/libalias.3 +++ b/sys/netinet/libalias/libalias.3 @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd December 25, 2013 +.Dd January 1, 2020 .Dt LIBALIAS 3 .Os .Sh NAME @@ -311,7 +311,7 @@ comprise the minimal set of functions needed for a basic IP masquerading implementation. .Pp .Ft int -.Fn LibAliasIn "struct libalias *" "char *buffer" "int maxpacketsize" +.Fn LibAliasIn "struct libalias *" "void *buffer" "int maxpacketsize" .Bd -ragged -offset indent An incoming packet coming from a remote machine to the local network is de-aliased by this function. @@ -352,7 +352,7 @@ An internal error within the packet aliasing engine occurred. .Ed .Pp .Ft int -.Fn LibAliasOut "struct libalias *" "char *buffer" "int maxpacketsize" +.Fn LibAliasOut "struct libalias *" "void *buffer" "int maxpacketsize" .Bd -ragged -offset indent An outgoing packet coming from the local network to a remote machine is aliased by this function. @@ -770,7 +770,7 @@ Fragments which arrive before the header are saved and then retrieved once the header fragment has been resolved. .Pp .Ft int -.Fn LibAliasSaveFragment "struct libalias *" "char *ptr" +.Fn LibAliasSaveFragment "struct libalias *" "void *ptr" .Bd -ragged -offset indent When .Fn LibAliasIn @@ -794,8 +794,8 @@ if it was successful and if there was an error. .Ed .Pp -.Ft char * -.Fn LibAliasGetFragment "struct libalias *" "char *buffer" +.Ft void * +.Fn LibAliasGetFragment "struct libalias *" "void *buffer" .Bd -ragged -offset indent This function can be used to retrieve fragment pointers saved by .Fn LibAliasSaveFragment . @@ -816,7 +816,7 @@ available, at which time it returns .Ed .Pp .Ft void -.Fn LibAliasFragmentIn "struct libalias *" "char *header" "char *fragment" +.Fn LibAliasFragmentIn "struct libalias *" "void *header" "void *fragment" .Bd -ragged -offset indent When a fragment is retrieved with .Fn LibAliasGetFragment , @@ -896,7 +896,7 @@ will return zero. .Ed .Pp .Ft int -.Fn LibAliasUnaliasOut "struct libalias *" "char *buffer" "int maxpacketsize" +.Fn LibAliasUnaliasOut "struct libalias *" "void *buffer" "int maxpacketsize" .Bd -ragged -offset indent An outgoing packet, which has already been aliased, has its private address/port information restored by this function.