From a7edfb5a47c80d7e0ba466c53780087f1d7f3a53 Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Wed, 3 Jul 2024 19:20:18 +0200 Subject: [PATCH 1/5] Fix log --- src/tcldcc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tcldcc.c b/src/tcldcc.c index 601714ba2..5e313832d 100644 --- a/src/tcldcc.c +++ b/src/tcldcc.c @@ -1134,7 +1134,7 @@ static int setlisten(Tcl_Interp *irp, char *ip, char *portp, char *type, char *m else if (IN6_IS_ADDR_UNSPECIFIED(&ipaddr6) && (!IN6_IS_ADDR_UNSPECIFIED(&dcc[idx].sockname.addr.s6.sin6_addr))) { Tcl_AppendResult(irp, "this port is already bound to a specific IP " - "on this machine, remove it before trying to bind to this all " + "on this machine, remove it before trying to bind to all " "interfaces", NULL); return TCL_ERROR; } From 5ddb7cf100c8c2504867593a8f51134b8eee5ab7 Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Wed, 3 Jul 2024 19:50:06 +0200 Subject: [PATCH 2/5] Enhance logging --- src/tcldcc.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/tcldcc.c b/src/tcldcc.c index 5e313832d..2df5fb7f1 100644 --- a/src/tcldcc.c +++ b/src/tcldcc.c @@ -1124,19 +1124,21 @@ static int setlisten(Tcl_Interp *irp, char *ip, char *portp, char *type, char *m /* Check if IP is all-interfaces, but the already-bound IP is specific */ if (ipv4) { if ((ipaddr4.s_addr == 0) && (dcc[idx].sockname.addr.s4.sin_addr.s_addr != 0)) { - Tcl_AppendResult(irp, "this port is already bound to a specific IP " - "on this machine, remove it before trying to bind to all " - "interfaces", NULL); + Tcl_AppendResult(irp, "this port is already bound to specific IP ", + inet_ntop(AF_INET, &dcc[idx].sockname.addr.s4.sin_addr, newip, sizeof newip), + " on this machine, remove it before trying to bind to all " + "interfaces", NULL); return TCL_ERROR; } } #ifdef IPV6 else if (IN6_IS_ADDR_UNSPECIFIED(&ipaddr6) && (!IN6_IS_ADDR_UNSPECIFIED(&dcc[idx].sockname.addr.s6.sin6_addr))) { - Tcl_AppendResult(irp, "this port is already bound to a specific IP " - "on this machine, remove it before trying to bind to all " - "interfaces", NULL); - return TCL_ERROR; + Tcl_AppendResult(irp, "this port is already bound to specific IP ", + inet_ntop(AF_INET6, &dcc[idx].sockname.addr.s6.sin6_addr, newip, sizeof newip), + " on this machine, remove it before trying to bind to all " + "interfaces", NULL); + return TCL_ERROR; } #endif } From 7e5ef677f82f26c59e93aa5e5b55f5b20e1acee8 Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Wed, 3 Jul 2024 22:19:23 +0200 Subject: [PATCH 3/5] Enhance log --- src/tcldcc.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/tcldcc.c b/src/tcldcc.c index 2df5fb7f1..f3641e47b 100644 --- a/src/tcldcc.c +++ b/src/tcldcc.c @@ -1107,16 +1107,18 @@ static int setlisten(Tcl_Interp *irp, char *ip, char *portp, char *type, char *m /* Check if IP is specific, but the already-bound IP is all-interfaces */ if (ipv4) { if ((ipaddr4.s_addr != 0) && (dcc[idx].sockname.addr.s4.sin_addr.s_addr == 0)) { - Tcl_AppendResult(irp, "this port is already bound to 0.0.0.0 on this " - "machine, remove it before trying to bind to this IP", NULL); + Tcl_AppendResult(irp, "This port is already bound to 0.0.0.0 on this " + "machine, remove it (using listen [ip] off) before " + "trying to bind to this IP.", NULL); return TCL_ERROR; } } #ifdef IPV6 else if ((!IN6_IS_ADDR_UNSPECIFIED(&ipaddr6)) && (IN6_IS_ADDR_UNSPECIFIED(&dcc[idx].sockname.addr.s6.sin6_addr))) { - Tcl_AppendResult(irp, "this port is already bound to :: on this " - "machine, remove it before trying to bind to this IP", NULL); + Tcl_AppendResult(irp, "This port is already bound to :: on this " + "machine, remove it (using listen [ip] off) before " + "trying to bind to this IP.", NULL); return TCL_ERROR; } #endif @@ -1124,20 +1126,20 @@ static int setlisten(Tcl_Interp *irp, char *ip, char *portp, char *type, char *m /* Check if IP is all-interfaces, but the already-bound IP is specific */ if (ipv4) { if ((ipaddr4.s_addr == 0) && (dcc[idx].sockname.addr.s4.sin_addr.s_addr != 0)) { - Tcl_AppendResult(irp, "this port is already bound to specific IP ", + Tcl_AppendResult(irp, "This port is already bound to specific IP ", inet_ntop(AF_INET, &dcc[idx].sockname.addr.s4.sin_addr, newip, sizeof newip), - " on this machine, remove it before trying to bind to all " - "interfaces", NULL); + " on this machine, remove it (using listen [ip] off) " + "before trying to bind to all interfaces.", NULL); return TCL_ERROR; } } #ifdef IPV6 else if (IN6_IS_ADDR_UNSPECIFIED(&ipaddr6) && (!IN6_IS_ADDR_UNSPECIFIED(&dcc[idx].sockname.addr.s6.sin6_addr))) { - Tcl_AppendResult(irp, "this port is already bound to specific IP ", + Tcl_AppendResult(irp, "This port is already bound to specific IP ", inet_ntop(AF_INET6, &dcc[idx].sockname.addr.s6.sin6_addr, newip, sizeof newip), - " on this machine, remove it before trying to bind to all " - "interfaces", NULL); + " on this machine, remove it (using listen [ip] off) " + "before trying to bind to all interfaces", NULL); return TCL_ERROR; } #endif @@ -1153,7 +1155,7 @@ static int setlisten(Tcl_Interp *irp, char *ip, char *portp, char *type, char *m } /* Remove */ if (idx < 0) { - Tcl_AppendResult(irp, "no such listen port is open", NULL); + Tcl_AppendResult(irp, "no such listen ip/port is open", NULL); return TCL_ERROR; } killsock(dcc[idx].sock); From 6a5948bf74218bd50313c65d3f0c97c37f34abdc Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Wed, 3 Jul 2024 22:42:09 +0200 Subject: [PATCH 4/5] do not exit eggdrop when rehashing --- src/tcldcc.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/tcldcc.c b/src/tcldcc.c index f3641e47b..ff000c7d2 100644 --- a/src/tcldcc.c +++ b/src/tcldcc.c @@ -1108,8 +1108,10 @@ static int setlisten(Tcl_Interp *irp, char *ip, char *portp, char *type, char *m if (ipv4) { if ((ipaddr4.s_addr != 0) && (dcc[idx].sockname.addr.s4.sin_addr.s_addr == 0)) { Tcl_AppendResult(irp, "This port is already bound to 0.0.0.0 on this " - "machine, remove it (using listen [ip] off) before " - "trying to bind to this IP.", NULL); + "machine, remove it (using listen [ip] off) before " + "trying to bind to this IP.", NULL); + if (do_restart == -2) /* do not exit eggdrop when rehashing */ + return TCL_OK; return TCL_ERROR; } } @@ -1119,6 +1121,8 @@ static int setlisten(Tcl_Interp *irp, char *ip, char *portp, char *type, char *m Tcl_AppendResult(irp, "This port is already bound to :: on this " "machine, remove it (using listen [ip] off) before " "trying to bind to this IP.", NULL); + if (do_restart == -2) /* do not exit eggdrop when rehashing */ + return TCL_OK; return TCL_ERROR; } #endif @@ -1130,6 +1134,8 @@ static int setlisten(Tcl_Interp *irp, char *ip, char *portp, char *type, char *m inet_ntop(AF_INET, &dcc[idx].sockname.addr.s4.sin_addr, newip, sizeof newip), " on this machine, remove it (using listen [ip] off) " "before trying to bind to all interfaces.", NULL); + if (do_restart == -2) /* do not exit eggdrop when rehashing */ + return TCL_OK; return TCL_ERROR; } } @@ -1140,6 +1146,8 @@ static int setlisten(Tcl_Interp *irp, char *ip, char *portp, char *type, char *m inet_ntop(AF_INET6, &dcc[idx].sockname.addr.s6.sin6_addr, newip, sizeof newip), " on this machine, remove it (using listen [ip] off) " "before trying to bind to all interfaces", NULL); + if (do_restart == -2) /* do not exit eggdrop when rehashing */ + return TCL_OK; return TCL_ERROR; } #endif From 16ec92406e93b6e4b8add776ab704a76bd975772 Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Wed, 3 Jul 2024 23:22:12 +0200 Subject: [PATCH 5/5] WIP --- src/tcldcc.c | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/src/tcldcc.c b/src/tcldcc.c index ff000c7d2..c1b015649 100644 --- a/src/tcldcc.c +++ b/src/tcldcc.c @@ -1024,7 +1024,7 @@ static int tcl_connect STDVAR static int setlisten(Tcl_Interp *irp, char *ip, char *portp, char *type, char *maskproc, char *flag) { int i, idx = -1, port, realport, found=0, ipv4=1, error; - char s[11], msg[256], newip[EGG_INET_ADDRSTRLEN]; + char s[11], msg[256], newip[EGG_INET_ADDRSTRLEN], newip2[EGG_INET_ADDRSTRLEN]; struct portmap *pmap = NULL, *pold = NULL; sockname_t name; struct in_addr ipaddr4; @@ -1109,9 +1109,17 @@ static int setlisten(Tcl_Interp *irp, char *ip, char *portp, char *type, char *m if ((ipaddr4.s_addr != 0) && (dcc[idx].sockname.addr.s4.sin_addr.s_addr == 0)) { Tcl_AppendResult(irp, "This port is already bound to 0.0.0.0 on this " "machine, remove it (using listen [ip] off) before " - "trying to bind to this IP.", NULL); - if (do_restart == -2) /* do not exit eggdrop when rehashing */ + "trying to bind to specific IP ", + inet_ntop(AF_INET, &ipaddr4.s_addr, newip, sizeof newip), + ".", NULL); + if (do_restart == -2) { /* do not exit eggdrop when rehashing */ + putlog(LOG_MISC, "*", "WARNING: Port %i is already bound to " + "0.0.0.0 on this machine, remove it (using listen [ip] " + "off) before trying to bind to specific IP %s, check listen settings " + "in config file or restart instead of rehash.", port, + inet_ntop(AF_INET, &ipaddr4.s_addr, newip, sizeof newip)); return TCL_OK; + } return TCL_ERROR; } } @@ -1121,8 +1129,13 @@ static int setlisten(Tcl_Interp *irp, char *ip, char *portp, char *type, char *m Tcl_AppendResult(irp, "This port is already bound to :: on this " "machine, remove it (using listen [ip] off) before " "trying to bind to this IP.", NULL); - if (do_restart == -2) /* do not exit eggdrop when rehashing */ + if (do_restart == -2) { /* do not exit eggdrop when rehashing */ + putlog(LOG_MISC, "*", "WARNING: Port %i is already bound to " + ":: on this machine, remove it (using listen [ip] " + "off) before trying to bind to this IP, check listen settings " + "in config file or restart instead of rehash.", port); return TCL_OK; + } return TCL_ERROR; } #endif @@ -1134,8 +1147,15 @@ static int setlisten(Tcl_Interp *irp, char *ip, char *portp, char *type, char *m inet_ntop(AF_INET, &dcc[idx].sockname.addr.s4.sin_addr, newip, sizeof newip), " on this machine, remove it (using listen [ip] off) " "before trying to bind to all interfaces.", NULL); - if (do_restart == -2) /* do not exit eggdrop when rehashing */ + if (do_restart == -2) { /* do not exit eggdrop when rehashing */ + putlog(LOG_MISC, "*", "WARNING: Port %i is already bound to " + "specific IP %s on this machine, remove it (using listen [ip] " + "off) before trying to bind to IP %s, check listen settings " + "in config file or restart instead of rehash.", port, + inet_ntop(AF_INET, &dcc[idx].sockname.addr.s4.sin_addr, newip, sizeof newip), + inet_ntop(AF_INET, &ipaddr4.s_addr, newip2, sizeof newip2)); return TCL_OK; + } return TCL_ERROR; } } @@ -1146,8 +1166,14 @@ static int setlisten(Tcl_Interp *irp, char *ip, char *portp, char *type, char *m inet_ntop(AF_INET6, &dcc[idx].sockname.addr.s6.sin6_addr, newip, sizeof newip), " on this machine, remove it (using listen [ip] off) " "before trying to bind to all interfaces", NULL); - if (do_restart == -2) /* do not exit eggdrop when rehashing */ + if (do_restart == -2) { /* do not exit eggdrop when rehashing */ + putlog(LOG_MISC, "*", "WARNING: Port %i is already bound to " + "specific IP %s on this machine, remove it (using listen [ip] " + "off) before trying to bind to this IP, check listen settings " + "in config file or restart instead of rehash.", port, + inet_ntop(AF_INET, &dcc[idx].sockname.addr.s6.sin6_addr, newip, sizeof newip)); return TCL_OK; + } return TCL_ERROR; } #endif