These should not change any behavior, they mostly clarify
the used types and silence warnings, since these casts are
deliberate.
Change-Id: Ica721a51b00d5314125bcaf5a586e718c5982aef
Signed-off-by: Frank Lichtenheld <frank@lichtenheld.com>
Acked-by: MaxF <max@max-fillinger.net>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1164
Message-Id: <20250926111726.153603-1-frank@lichtenheld.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg33218.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
| ... | ... |
@@ -185,11 +185,7 @@ client_nat_transform(const struct client_nat_option_list *list, struct buffer *i |
| 185 | 185 |
const int direction) |
| 186 | 186 |
{
|
| 187 | 187 |
struct ip_tcp_udp_hdr *h = (struct ip_tcp_udp_hdr *)BPTR(ipbuf); |
| 188 |
- int i; |
|
| 189 |
- uint32_t addr, *addr_ptr; |
|
| 190 |
- const uint32_t *from, *to; |
|
| 191 |
- int accumulate = 0; |
|
| 192 |
- unsigned int amask; |
|
| 188 |
+ int32_t accumulate = 0; |
|
| 193 | 189 |
unsigned int alog = 0; |
| 194 | 190 |
|
| 195 | 191 |
if (check_debug_level(D_CLIENT_NAT)) |
| ... | ... |
@@ -197,8 +193,11 @@ client_nat_transform(const struct client_nat_option_list *list, struct buffer *i |
| 197 | 197 |
print_pkt(&h->ip, "BEFORE", direction, D_CLIENT_NAT); |
| 198 | 198 |
} |
| 199 | 199 |
|
| 200 |
- for (i = 0; i < list->n; ++i) |
|
| 200 |
+ for (int i = 0; i < list->n; ++i) |
|
| 201 | 201 |
{
|
| 202 |
+ uint32_t addr, *addr_ptr; |
|
| 203 |
+ const uint32_t *from, *to; |
|
| 204 |
+ unsigned int amask; |
|
| 202 | 205 |
const struct client_nat_entry *e = &list->entries[i]; /* current NAT rule */ |
| 203 | 206 |
if (e->type ^ direction) |
| 204 | 207 |
{
|
| ... | ... |
@@ -130,11 +130,6 @@ mss_fixup_ipv6(struct buffer *buf, uint16_t maxmss) |
| 130 | 130 |
} |
| 131 | 131 |
} |
| 132 | 132 |
|
| 133 |
-#if defined(__GNUC__) || defined(__clang__) |
|
| 134 |
-#pragma GCC diagnostic push |
|
| 135 |
-#pragma GCC diagnostic ignored "-Wconversion" |
|
| 136 |
-#endif |
|
| 137 |
- |
|
| 138 | 133 |
/* |
| 139 | 134 |
* change TCP MSS option in SYN/SYN-ACK packets, if present |
| 140 | 135 |
* this is generic for IPv4 and IPv6, as the TCP header is the same |
| ... | ... |
@@ -143,11 +138,8 @@ mss_fixup_ipv6(struct buffer *buf, uint16_t maxmss) |
| 143 | 143 |
void |
| 144 | 144 |
mss_fixup_dowork(struct buffer *buf, uint16_t maxmss) |
| 145 | 145 |
{
|
| 146 |
- int hlen, olen, optlen; |
|
| 146 |
+ int olen, optlen; |
|
| 147 | 147 |
uint8_t *opt; |
| 148 |
- uint16_t mssval; |
|
| 149 |
- int accumulate; |
|
| 150 |
- struct openvpn_tcphdr *tc; |
|
| 151 | 148 |
|
| 152 | 149 |
if (BLEN(buf) < (int)sizeof(struct openvpn_tcphdr)) |
| 153 | 150 |
{
|
| ... | ... |
@@ -155,8 +147,8 @@ mss_fixup_dowork(struct buffer *buf, uint16_t maxmss) |
| 155 | 155 |
} |
| 156 | 156 |
|
| 157 | 157 |
verify_align_4(buf); |
| 158 |
- tc = (struct openvpn_tcphdr *)BPTR(buf); |
|
| 159 |
- hlen = OPENVPN_TCPH_GET_DOFF(tc->doff_res); |
|
| 158 |
+ struct openvpn_tcphdr *tc = (struct openvpn_tcphdr *)BPTR(buf); |
|
| 159 |
+ int hlen = OPENVPN_TCPH_GET_DOFF(tc->doff_res); |
|
| 160 | 160 |
|
| 161 | 161 |
/* Invalid header length or header without options. */ |
| 162 | 162 |
if (hlen <= (int)sizeof(struct openvpn_tcphdr) || hlen > BLEN(buf)) |
| ... | ... |
@@ -171,43 +163,37 @@ mss_fixup_dowork(struct buffer *buf, uint16_t maxmss) |
| 171 | 171 |
{
|
| 172 | 172 |
break; |
| 173 | 173 |
} |
| 174 |
- else if (*opt == OPENVPN_TCPOPT_NOP) |
|
| 174 |
+ if (*opt == OPENVPN_TCPOPT_NOP) |
|
| 175 | 175 |
{
|
| 176 | 176 |
optlen = 1; |
| 177 |
+ continue; |
|
| 178 |
+ } |
|
| 179 |
+ |
|
| 180 |
+ optlen = *(opt + 1); |
|
| 181 |
+ if (optlen <= 0 || optlen > olen) |
|
| 182 |
+ {
|
|
| 183 |
+ break; |
|
| 177 | 184 |
} |
| 178 |
- else |
|
| 185 |
+ if (*opt == OPENVPN_TCPOPT_MAXSEG) |
|
| 179 | 186 |
{
|
| 180 |
- optlen = *(opt + 1); |
|
| 181 |
- if (optlen <= 0 || optlen > olen) |
|
| 187 |
+ if (optlen != OPENVPN_TCPOLEN_MAXSEG) |
|
| 182 | 188 |
{
|
| 183 |
- break; |
|
| 189 |
+ continue; |
|
| 184 | 190 |
} |
| 185 |
- if (*opt == OPENVPN_TCPOPT_MAXSEG) |
|
| 191 |
+ uint16_t mssval = (uint16_t)(opt[2] << 8) + opt[3]; |
|
| 192 |
+ if (mssval > maxmss) |
|
| 186 | 193 |
{
|
| 187 |
- if (optlen != OPENVPN_TCPOLEN_MAXSEG) |
|
| 188 |
- {
|
|
| 189 |
- continue; |
|
| 190 |
- } |
|
| 191 |
- mssval = opt[2] << 8; |
|
| 192 |
- mssval += opt[3]; |
|
| 193 |
- if (mssval > maxmss) |
|
| 194 |
- {
|
|
| 195 |
- dmsg(D_MSS, "MSS: %" PRIu16 " -> %" PRIu16, mssval, maxmss); |
|
| 196 |
- accumulate = htons(mssval); |
|
| 197 |
- opt[2] = (uint8_t)((maxmss >> 8) & 0xff); |
|
| 198 |
- opt[3] = (uint8_t)(maxmss & 0xff); |
|
| 199 |
- accumulate -= htons(maxmss); |
|
| 200 |
- ADJUST_CHECKSUM(accumulate, tc->check); |
|
| 201 |
- } |
|
| 194 |
+ dmsg(D_MSS, "MSS: %" PRIu16 " -> %" PRIu16, mssval, maxmss); |
|
| 195 |
+ opt[2] = (uint8_t)((maxmss >> 8) & 0xff); |
|
| 196 |
+ opt[3] = (uint8_t)(maxmss & 0xff); |
|
| 197 |
+ int32_t accumulate = htons(mssval); |
|
| 198 |
+ accumulate -= htons(maxmss); |
|
| 199 |
+ ADJUST_CHECKSUM(accumulate, tc->check); |
|
| 202 | 200 |
} |
| 203 | 201 |
} |
| 204 | 202 |
} |
| 205 | 203 |
} |
| 206 | 204 |
|
| 207 |
-#if defined(__GNUC__) || defined(__clang__) |
|
| 208 |
-#pragma GCC diagnostic pop |
|
| 209 |
-#endif |
|
| 210 |
- |
|
| 211 | 205 |
static inline size_t |
| 212 | 206 |
adjust_payload_max_cbc(const struct key_type *kt, size_t target) |
| 213 | 207 |
{
|
| ... | ... |
@@ -214,7 +214,7 @@ struct ip_tcp_udp_hdr |
| 214 | 214 |
*/ |
| 215 | 215 |
#define ADJUST_CHECKSUM(acc, cksum) \ |
| 216 | 216 |
{ \
|
| 217 |
- int _acc = acc; \ |
|
| 217 |
+ int32_t _acc = acc; \ |
|
| 218 | 218 |
_acc += (cksum); \ |
| 219 | 219 |
if (_acc < 0) \ |
| 220 | 220 |
{ \
|
| ... | ... |
@@ -231,16 +231,16 @@ struct ip_tcp_udp_hdr |
| 231 | 231 |
} \ |
| 232 | 232 |
} |
| 233 | 233 |
|
| 234 |
-#define ADD_CHECKSUM_32(acc, u32) \ |
|
| 235 |
- { \
|
|
| 236 |
- acc += (u32) & 0xffff; \ |
|
| 237 |
- acc += (u32) >> 16; \ |
|
| 234 |
+#define ADD_CHECKSUM_32(acc, u32) \ |
|
| 235 |
+ { \
|
|
| 236 |
+ acc += (int32_t)((u32) & 0xffff); \ |
|
| 237 |
+ acc += (int32_t)((u32) >> 16); \ |
|
| 238 | 238 |
} |
| 239 | 239 |
|
| 240 |
-#define SUB_CHECKSUM_32(acc, u32) \ |
|
| 241 |
- { \
|
|
| 242 |
- acc -= (u32) & 0xffff; \ |
|
| 243 |
- acc -= (u32) >> 16; \ |
|
| 240 |
+#define SUB_CHECKSUM_32(acc, u32) \ |
|
| 241 |
+ { \
|
|
| 242 |
+ acc -= (int32_t)((u32) & 0xffff); \ |
|
| 243 |
+ acc -= (int32_t)((u32) >> 16); \ |
|
| 244 | 244 |
} |
| 245 | 245 |
|
| 246 | 246 |
/* |