Skip to content

Commit a06b9b2

Browse files
flichtenheldcron2
authored andcommitted
proto: Clean up conversion warnings related to checksum macros
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 <[email protected]> Acked-by: MaxF <[email protected]> Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1164 Message-Id: <[email protected]> URL: https://www.mail-archive.com/[email protected]/msg33218.html Signed-off-by: Gert Doering <[email protected]>
1 parent 5b8e056 commit a06b9b2

File tree

3 files changed

+36
-51
lines changed

3 files changed

+36
-51
lines changed

src/openvpn/clinat.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,20 +185,19 @@ client_nat_transform(const struct client_nat_option_list *list, struct buffer *i
185185
const int direction)
186186
{
187187
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;
193189
unsigned int alog = 0;
194190

195191
if (check_debug_level(D_CLIENT_NAT))
196192
{
197193
print_pkt(&h->ip, "BEFORE", direction, D_CLIENT_NAT);
198194
}
199195

200-
for (i = 0; i < list->n; ++i)
196+
for (int i = 0; i < list->n; ++i)
201197
{
198+
uint32_t addr, *addr_ptr;
199+
const uint32_t *from, *to;
200+
unsigned int amask;
202201
const struct client_nat_entry *e = &list->entries[i]; /* current NAT rule */
203202
if (e->type ^ direction)
204203
{

src/openvpn/mss.c

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,6 @@ mss_fixup_ipv6(struct buffer *buf, uint16_t maxmss)
130130
}
131131
}
132132

133-
#if defined(__GNUC__) || defined(__clang__)
134-
#pragma GCC diagnostic push
135-
#pragma GCC diagnostic ignored "-Wconversion"
136-
#endif
137-
138133
/*
139134
* change TCP MSS option in SYN/SYN-ACK packets, if present
140135
* this is generic for IPv4 and IPv6, as the TCP header is the same
@@ -143,20 +138,17 @@ mss_fixup_ipv6(struct buffer *buf, uint16_t maxmss)
143138
void
144139
mss_fixup_dowork(struct buffer *buf, uint16_t maxmss)
145140
{
146-
int hlen, olen, optlen;
141+
int olen, optlen;
147142
uint8_t *opt;
148-
uint16_t mssval;
149-
int accumulate;
150-
struct openvpn_tcphdr *tc;
151143

152144
if (BLEN(buf) < (int)sizeof(struct openvpn_tcphdr))
153145
{
154146
return;
155147
}
156148

157149
verify_align_4(buf);
158-
tc = (struct openvpn_tcphdr *)BPTR(buf);
159-
hlen = OPENVPN_TCPH_GET_DOFF(tc->doff_res);
150+
struct openvpn_tcphdr *tc = (struct openvpn_tcphdr *)BPTR(buf);
151+
int hlen = OPENVPN_TCPH_GET_DOFF(tc->doff_res);
160152

161153
/* Invalid header length or header without options. */
162154
if (hlen <= (int)sizeof(struct openvpn_tcphdr) || hlen > BLEN(buf))
@@ -171,43 +163,37 @@ mss_fixup_dowork(struct buffer *buf, uint16_t maxmss)
171163
{
172164
break;
173165
}
174-
else if (*opt == OPENVPN_TCPOPT_NOP)
166+
if (*opt == OPENVPN_TCPOPT_NOP)
175167
{
176168
optlen = 1;
169+
continue;
170+
}
171+
172+
optlen = *(opt + 1);
173+
if (optlen <= 0 || optlen > olen)
174+
{
175+
break;
177176
}
178-
else
177+
if (*opt == OPENVPN_TCPOPT_MAXSEG)
179178
{
180-
optlen = *(opt + 1);
181-
if (optlen <= 0 || optlen > olen)
179+
if (optlen != OPENVPN_TCPOLEN_MAXSEG)
182180
{
183-
break;
181+
continue;
184182
}
185-
if (*opt == OPENVPN_TCPOPT_MAXSEG)
183+
uint16_t mssval = (uint16_t)(opt[2] << 8) + opt[3];
184+
if (mssval > maxmss)
186185
{
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-
}
186+
dmsg(D_MSS, "MSS: %" PRIu16 " -> %" PRIu16, mssval, maxmss);
187+
opt[2] = (uint8_t)((maxmss >> 8) & 0xff);
188+
opt[3] = (uint8_t)(maxmss & 0xff);
189+
int32_t accumulate = htons(mssval);
190+
accumulate -= htons(maxmss);
191+
ADJUST_CHECKSUM(accumulate, tc->check);
202192
}
203193
}
204194
}
205195
}
206196

207-
#if defined(__GNUC__) || defined(__clang__)
208-
#pragma GCC diagnostic pop
209-
#endif
210-
211197
static inline size_t
212198
adjust_payload_max_cbc(const struct key_type *kt, size_t target)
213199
{

src/openvpn/proto.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ struct ip_tcp_udp_hdr
214214
*/
215215
#define ADJUST_CHECKSUM(acc, cksum) \
216216
{ \
217-
int _acc = acc; \
217+
int32_t _acc = acc; \
218218
_acc += (cksum); \
219219
if (_acc < 0) \
220220
{ \
@@ -231,16 +231,16 @@ struct ip_tcp_udp_hdr
231231
} \
232232
}
233233

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); \
238238
}
239239

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); \
244244
}
245245

246246
/*

0 commit comments

Comments
 (0)