Skip to content

Commit

Permalink
Add warning if firewall blocks loopback (closes #2621)
Browse files Browse the repository at this point in the history
  • Loading branch information
zuckschwerdt committed Oct 2, 2023
1 parent 72c0f21 commit 596c3d6
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/mongoose.c
Original file line number Diff line number Diff line change
Expand Up @@ -3459,14 +3459,17 @@ void mg_broadcast(struct mg_mgr *mgr, mg_event_handler_t cb, void *data,
*/
if (mgr->ctl[0] != INVALID_SOCKET && data != NULL &&
len < sizeof(ctl_msg.message)) {
size_t dummy;
size_t ret;

ctl_msg.callback = cb;
memcpy(ctl_msg.message, data, len);
dummy = MG_SEND_FUNC(mgr->ctl[0], (char *) &ctl_msg,
ret = MG_SEND_FUNC(mgr->ctl[0], (char *) &ctl_msg,
offsetof(struct ctl_msg, message) + len, 0);
dummy = MG_RECV_FUNC(mgr->ctl[0], (char *) &len, 1, 0);
(void) dummy; /* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25509 */
if (ret < 0)
perror("mg_broadcast() send failed, check UDP loopback device");
ret = MG_RECV_FUNC(mgr->ctl[0], (char *) &len, 1, 0);
if (ret < 0)
perror("mg_broadcast() recv failed, check firewall UDP loopback rules");
}
}
#endif /* MG_ENABLE_BROADCAST */
Expand Down Expand Up @@ -4116,9 +4119,12 @@ static void mg_mgr_handle_ctl_sock(struct mg_mgr *mgr) {
struct ctl_msg ctl_msg;
int len =
(int) MG_RECV_FUNC(mgr->ctl[1], (char *) &ctl_msg, sizeof(ctl_msg), 0);
size_t dummy = MG_SEND_FUNC(mgr->ctl[1], ctl_msg.message, 1, 0);
if (len < 0)
perror("mg_mgr_handle_ctl_sock() recv failed, check firewall UDP loopback rules");
size_t ret = MG_SEND_FUNC(mgr->ctl[1], ctl_msg.message, 1, 0);
if (ret < 0)
perror("mg_mgr_handle_ctl_sock() send failed, check UDP loopback device");
DBG(("read %d from ctl socket", len));
(void) dummy; /* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25509 */
if (len >= (int) sizeof(ctl_msg.callback) && ctl_msg.callback != NULL) {
struct mg_connection *nc;
for (nc = mg_next(mgr, NULL); nc != NULL; nc = mg_next(mgr, nc)) {
Expand Down
41 changes: 41 additions & 0 deletions src/mongoose_broadcast.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
diff --git a/src/mongoose.c b/src/mongoose.c
index c9c40863..55bd01e1 100644
--- a/src/mongoose.c
+++ b/src/mongoose.c
@@ -3459,14 +3459,17 @@ void mg_broadcast(struct mg_mgr *mgr, mg_event_handler_t cb, void *data,
*/
if (mgr->ctl[0] != INVALID_SOCKET && data != NULL &&
len < sizeof(ctl_msg.message)) {
- size_t dummy;
+ size_t ret;

ctl_msg.callback = cb;
memcpy(ctl_msg.message, data, len);
- dummy = MG_SEND_FUNC(mgr->ctl[0], (char *) &ctl_msg,
+ ret = MG_SEND_FUNC(mgr->ctl[0], (char *) &ctl_msg,
offsetof(struct ctl_msg, message) + len, 0);
- dummy = MG_RECV_FUNC(mgr->ctl[0], (char *) &len, 1, 0);
- (void) dummy; /* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25509 */
+ if (ret < 0)
+ perror("mg_broadcast() send failed, check UDP loopback device");
+ ret = MG_RECV_FUNC(mgr->ctl[0], (char *) &len, 1, 0);
+ if (ret < 0)
+ perror("mg_broadcast() recv failed, check firewall UDP loopback rules");
}
}
#endif /* MG_ENABLE_BROADCAST */
@@ -4116,9 +4119,12 @@ static void mg_mgr_handle_ctl_sock(struct mg_mgr *mgr) {
struct ctl_msg ctl_msg;
int len =
(int) MG_RECV_FUNC(mgr->ctl[1], (char *) &ctl_msg, sizeof(ctl_msg), 0);
- size_t dummy = MG_SEND_FUNC(mgr->ctl[1], ctl_msg.message, 1, 0);
+ if (len < 0)
+ perror("mg_mgr_handle_ctl_sock() recv failed, check firewall UDP loopback rules");
+ size_t ret = MG_SEND_FUNC(mgr->ctl[1], ctl_msg.message, 1, 0);
+ if (ret < 0)
+ perror("mg_mgr_handle_ctl_sock() send failed, check UDP loopback device");
DBG(("read %d from ctl socket", len));
- (void) dummy; /* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25509 */
if (len >= (int) sizeof(ctl_msg.callback) && ctl_msg.callback != NULL) {
struct mg_connection *nc;
for (nc = mg_next(mgr, NULL); nc != NULL; nc = mg_next(mgr, nc)) {

0 comments on commit 596c3d6

Please sign in to comment.