Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(WIP) Fix and enhance logging for port already bound #1634

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 51 additions & 13 deletions src/tcldcc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1107,36 +1107,74 @@ 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] <port> off) before "
"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] <port> "
"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;
}
}
#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] <port> off) before "
"trying to bind to this IP.", NULL);
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] <port> "
"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

/* 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 (using listen [ip] <port> off) "
"before trying to bind to all interfaces.", NULL);
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] <port> "
"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;
}
}
#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 this 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 (using listen [ip] <port> off) "
"before trying to bind to all interfaces", NULL);
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] <port> "
"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
}
Expand All @@ -1151,7 +1189,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);
Expand Down