Move the check that calls this function into the calling function.
Also eliminate the if (len) check in the
check_incoming_control_channel_dowork function as it is only called
if len is > 0 anyway and replace it with a ASSERT.
Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20200810143707.5834-11-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg20680.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
| ... | ... |
@@ -122,21 +122,6 @@ check_tls_errors(struct context *c) |
| 122 | 122 |
} |
| 123 | 123 |
|
| 124 | 124 |
/* |
| 125 |
- * Check for possible incoming configuration |
|
| 126 |
- * messages on the control channel. |
|
| 127 |
- */ |
|
| 128 |
-static inline void |
|
| 129 |
-check_incoming_control_channel(struct context *c) |
|
| 130 |
-{
|
|
| 131 |
-#if P2MP |
|
| 132 |
- if (tls_test_payload_len(c->c2.tls_multi) > 0) |
|
| 133 |
- {
|
|
| 134 |
- check_incoming_control_channel_dowork(c); |
|
| 135 |
- } |
|
| 136 |
-#endif |
|
| 137 |
-} |
|
| 138 |
- |
|
| 139 |
-/* |
|
| 140 | 125 |
* Set our wakeup to 0 seconds, so we will be rescheduled |
| 141 | 126 |
* immediately. |
| 142 | 127 |
*/ |
| ... | ... |
@@ -222,61 +207,61 @@ check_tls_errors_nco(struct context *c) |
| 222 | 222 |
* messages on the control channel. |
| 223 | 223 |
*/ |
| 224 | 224 |
void |
| 225 |
-check_incoming_control_channel_dowork(struct context *c) |
|
| 225 |
+check_incoming_control_channel(struct context *c) |
|
| 226 | 226 |
{
|
| 227 |
- const int len = tls_test_payload_len(c->c2.tls_multi); |
|
| 228 |
- if (len) |
|
| 227 |
+ int len = tls_test_payload_len(c->c2.tls_multi); |
|
| 228 |
+ /* We should only be called with len >0 */ |
|
| 229 |
+ ASSERT(len > 0); |
|
| 230 |
+ |
|
| 231 |
+ struct gc_arena gc = gc_new(); |
|
| 232 |
+ struct buffer buf = alloc_buf_gc(len, &gc); |
|
| 233 |
+ if (tls_rec_payload(c->c2.tls_multi, &buf)) |
|
| 229 | 234 |
{
|
| 230 |
- struct gc_arena gc = gc_new(); |
|
| 231 |
- struct buffer buf = alloc_buf_gc(len, &gc); |
|
| 232 |
- if (tls_rec_payload(c->c2.tls_multi, &buf)) |
|
| 233 |
- {
|
|
| 234 |
- /* force null termination of message */ |
|
| 235 |
- buf_null_terminate(&buf); |
|
| 235 |
+ /* force null termination of message */ |
|
| 236 |
+ buf_null_terminate(&buf); |
|
| 236 | 237 |
|
| 237 |
- /* enforce character class restrictions */ |
|
| 238 |
- string_mod(BSTR(&buf), CC_PRINT, CC_CRLF, 0); |
|
| 238 |
+ /* enforce character class restrictions */ |
|
| 239 |
+ string_mod(BSTR(&buf), CC_PRINT, CC_CRLF, 0); |
|
| 239 | 240 |
|
| 240 |
- if (buf_string_match_head_str(&buf, "AUTH_FAILED")) |
|
| 241 |
- {
|
|
| 242 |
- receive_auth_failed(c, &buf); |
|
| 243 |
- } |
|
| 244 |
- else if (buf_string_match_head_str(&buf, "PUSH_")) |
|
| 245 |
- {
|
|
| 246 |
- incoming_push_message(c, &buf); |
|
| 247 |
- } |
|
| 248 |
- else if (buf_string_match_head_str(&buf, "RESTART")) |
|
| 249 |
- {
|
|
| 250 |
- server_pushed_signal(c, &buf, true, 7); |
|
| 251 |
- } |
|
| 252 |
- else if (buf_string_match_head_str(&buf, "HALT")) |
|
| 253 |
- {
|
|
| 254 |
- server_pushed_signal(c, &buf, false, 4); |
|
| 255 |
- } |
|
| 256 |
- else if (buf_string_match_head_str(&buf, "INFO_PRE")) |
|
| 257 |
- {
|
|
| 258 |
- server_pushed_info(c, &buf, 8); |
|
| 259 |
- } |
|
| 260 |
- else if (buf_string_match_head_str(&buf, "INFO")) |
|
| 261 |
- {
|
|
| 262 |
- server_pushed_info(c, &buf, 4); |
|
| 263 |
- } |
|
| 264 |
- else if (buf_string_match_head_str(&buf, "CR_RESPONSE")) |
|
| 265 |
- {
|
|
| 266 |
- receive_cr_response(c, &buf); |
|
| 267 |
- } |
|
| 268 |
- else |
|
| 269 |
- {
|
|
| 270 |
- msg(D_PUSH_ERRORS, "WARNING: Received unknown control message: %s", BSTR(&buf)); |
|
| 271 |
- } |
|
| 241 |
+ if (buf_string_match_head_str(&buf, "AUTH_FAILED")) |
|
| 242 |
+ {
|
|
| 243 |
+ receive_auth_failed(c, &buf); |
|
| 244 |
+ } |
|
| 245 |
+ else if (buf_string_match_head_str(&buf, "PUSH_")) |
|
| 246 |
+ {
|
|
| 247 |
+ incoming_push_message(c, &buf); |
|
| 248 |
+ } |
|
| 249 |
+ else if (buf_string_match_head_str(&buf, "RESTART")) |
|
| 250 |
+ {
|
|
| 251 |
+ server_pushed_signal(c, &buf, true, 7); |
|
| 252 |
+ } |
|
| 253 |
+ else if (buf_string_match_head_str(&buf, "HALT")) |
|
| 254 |
+ {
|
|
| 255 |
+ server_pushed_signal(c, &buf, false, 4); |
|
| 256 |
+ } |
|
| 257 |
+ else if (buf_string_match_head_str(&buf, "INFO_PRE")) |
|
| 258 |
+ {
|
|
| 259 |
+ server_pushed_info(c, &buf, 8); |
|
| 260 |
+ } |
|
| 261 |
+ else if (buf_string_match_head_str(&buf, "INFO")) |
|
| 262 |
+ {
|
|
| 263 |
+ server_pushed_info(c, &buf, 4); |
|
| 264 |
+ } |
|
| 265 |
+ else if (buf_string_match_head_str(&buf, "CR_RESPONSE")) |
|
| 266 |
+ {
|
|
| 267 |
+ receive_cr_response(c, &buf); |
|
| 272 | 268 |
} |
| 273 | 269 |
else |
| 274 | 270 |
{
|
| 275 |
- msg(D_PUSH_ERRORS, "WARNING: Receive control message failed"); |
|
| 271 |
+ msg(D_PUSH_ERRORS, "WARNING: Received unknown control message: %s", BSTR(&buf)); |
|
| 276 | 272 |
} |
| 277 |
- |
|
| 278 |
- gc_free(&gc); |
|
| 279 | 273 |
} |
| 274 |
+ else |
|
| 275 |
+ {
|
|
| 276 |
+ msg(D_PUSH_ERRORS, "WARNING: Receive control message failed"); |
|
| 277 |
+ } |
|
| 278 |
+ |
|
| 279 |
+ gc_free(&gc); |
|
| 280 | 280 |
} |
| 281 | 281 |
|
| 282 | 282 |
/* |
| ... | ... |
@@ -1877,8 +1862,14 @@ pre_select(struct context *c) |
| 1877 | 1877 |
return; |
| 1878 | 1878 |
} |
| 1879 | 1879 |
|
| 1880 |
- /* check for incoming configuration info on the control channel */ |
|
| 1881 |
- check_incoming_control_channel(c); |
|
| 1880 |
+#if P2MP |
|
| 1881 |
+ /* check for incoming control messages on the control channel like |
|
| 1882 |
+ * push request/reply, or authentication failure and 2FA messages */ |
|
| 1883 |
+ if (tls_test_payload_len(c->c2.tls_multi) > 0) |
|
| 1884 |
+ {
|
|
| 1885 |
+ check_incoming_control_channel(c); |
|
| 1886 |
+ } |
|
| 1887 |
+#endif |
|
| 1882 | 1888 |
|
| 1883 | 1889 |
/* Should we send an OCC message? */ |
| 1884 | 1890 |
check_send_occ_msg(c); |
| ... | ... |
@@ -75,7 +75,7 @@ void check_tls_errors_co(struct context *c); |
| 75 | 75 |
void check_tls_errors_nco(struct context *c); |
| 76 | 76 |
|
| 77 | 77 |
#if P2MP |
| 78 |
-void check_incoming_control_channel_dowork(struct context *c); |
|
| 78 |
+void check_incoming_control_channel(struct context *c); |
|
| 79 | 79 |
|
| 80 | 80 |
void check_scheduled_exit(struct context *c); |
| 81 | 81 |
|