From e75cb1709dbd6ebd8dfb0f69ff7e51f76f53aded Mon Sep 17 00:00:00 2001 From: Heero Date: Tue, 3 Jun 2014 23:39:30 -0700 Subject: [PATCH] [4246] Add set::link::bind-ip option to set default bind ip for link blocks --- include/dynconf.h | 2 ++ src/modules/m_stats.c | 3 +++ src/s_bsd.c | 13 ++++++++++--- src/s_conf.c | 31 +++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 3 deletions(-) diff --git a/include/dynconf.h b/include/dynconf.h index a90db217d..1aceed6b4 100644 --- a/include/dynconf.h +++ b/include/dynconf.h @@ -80,6 +80,7 @@ struct zConfiguration { int host_retries; char *name_server; char *dns_bindip; + char *link_bindip; long throttle_period; char throttle_count; char *kline_address; @@ -186,6 +187,7 @@ extern MODVAR aConfiguration iConf; #define HOST_RETRIES iConf.host_retries #define NAME_SERVER iConf.name_server #define DNS_BINDIP iConf.dns_bindip +#define LINK_BINDIP iConf.link_bindip #define IDENT_CHECK iConf.ident_check #define FAILOPER_WARN iConf.fail_oper_warn #define SHOWCONNECTINFO iConf.show_connect_info diff --git a/src/modules/m_stats.c b/src/modules/m_stats.c index b8dd77794..4af67e270 100644 --- a/src/modules/m_stats.c +++ b/src/modules/m_stats.c @@ -1285,6 +1285,9 @@ int stats_set(aClient *sptr, char *para) sptr->name, DNS_BINDIP); sendto_one(sptr, ":%s %i %s :ban-version-tkl-time: %s", me.name, RPL_TEXT, sptr->name, pretty_time_val(BAN_VERSION_TKL_TIME)); + if (LINK_BINDIP) + sendto_one(sptr, ":%s %i %s :link::bind-ip: %s", me.name, RPL_TEXT, + sptr->name, LINK_BINDIP); sendto_one(sptr, ":%s %i %s :throttle::period: %s", me.name, RPL_TEXT, sptr->name, THROTTLING_PERIOD ? pretty_time_val(THROTTLING_PERIOD) : "disabled"); sendto_one(sptr, ":%s %i %s :throttle::connections: %d", me.name, RPL_TEXT, diff --git a/src/s_bsd.c b/src/s_bsd.c index fe784ed3e..9e45b2a9b 100644 --- a/src/s_bsd.c +++ b/src/s_bsd.c @@ -1664,6 +1664,7 @@ static struct SOCKADDR *connect_inet(ConfigItem_link *aconf, aClient *cptr, int { static struct SOCKADDR_IN server; struct hostent *hp; + char *bindip; char buf[BUFSIZE]; /* @@ -1692,15 +1693,21 @@ static struct SOCKADDR *connect_inet(ConfigItem_link *aconf, aClient *cptr, int get_sockhost(cptr, aconf->hostname); - if (aconf->bindip && strcmp("*", aconf->bindip)) + + if (!aconf->bindip && iConf.link_bindip) + bindip = iConf.link_bindip; + else + bindip = aconf->bindip; + + if (bindip && strcmp("*", bindip)) { bzero((char *)&server, sizeof(server)); server.SIN_FAMILY = AFINET; server.SIN_PORT = 0; #ifndef INET6 - server.SIN_ADDR.S_ADDR = inet_addr(aconf->bindip); + server.SIN_ADDR.S_ADDR = inet_addr(bindip); #else - inet_pton(AF_INET6, aconf->bindip, server.SIN_ADDR.S_ADDR); + inet_pton(AF_INET6, bindip, server.SIN_ADDR.S_ADDR); #endif if (bind(cptr->fd, (struct SOCKADDR *)&server, sizeof(server)) == -1) { diff --git a/src/s_conf.c b/src/s_conf.c index 3452a516b..97f518c93 100644 --- a/src/s_conf.c +++ b/src/s_conf.c @@ -6068,6 +6068,7 @@ int _conf_link(ConfigFile *conf, ConfigEntry *ce) link = (ConfigItem_link *) MyMallocEx(sizeof(ConfigItem_link)); link->servername = strdup(ce->ce_vardata); + /* ugly, but it works. if it fails, we know _test_link failed miserably */ for (cep = ce->ce_entries; cep; cep = cep->ce_next) { @@ -6116,6 +6117,7 @@ int _conf_link(ConfigFile *conf, ConfigEntry *ce) link->ciphers = strdup(cep->ce_vardata); #endif } + AddListItem(link, conf_link); return 0; } @@ -7004,6 +7006,13 @@ int _conf_set(ConfigFile *conf, ConfigEntry *ce) else ircstrdup(tempiConf.network.x_prefix_quit, cep->ce_vardata); } + else if (!strcmp(cep->ce_varname, "link")) { + for (cepp = cep->ce_entries; cepp; cepp = cepp->ce_next) { + if (!strcmp(cepp->ce_varname, "bind-ip")) { + ircstrdup(tempiConf.link_bindip, cepp->ce_vardata); + } + } + } else if (!strcmp(cep->ce_varname, "dns")) { for (cepp = cep->ce_entries; cepp; cepp = cepp->ce_next) { if (!strcmp(cepp->ce_varname, "timeout")) { @@ -7018,6 +7027,7 @@ int _conf_set(ConfigFile *conf, ConfigEntry *ce) else if (!strcmp(cepp->ce_varname, "bind-ip")) { ircstrdup(tempiConf.dns_bindip, cepp->ce_vardata); } + } } else if (!strcmp(cep->ce_varname, "throttle")) { @@ -7657,6 +7667,27 @@ int _test_set(ConfigFile *conf, ConfigEntry *ce) CheckDuplicate(cep, new_linking_protocol, "new-linking-protocol"); CheckNull(cep); } + else if (!strcmp(cep->ce_varname, "link")) { + for (cepp = cep->ce_entries; cepp; cepp = cepp->ce_next) { + CheckNull(cepp); + if (!strcmp(cepp->ce_varname, "bind-ip")) { + struct in_addr in; + CheckDuplicate(cepp, dns_bind_ip, "link::bind-ip"); + if (strcmp(cepp->ce_vardata, "*")) + { + in.s_addr = inet_addr(cepp->ce_vardata); + if (strcmp((char *)inet_ntoa(in), cepp->ce_vardata)) + { + config_error("%s:%i: set::link::bind-ip (%s) is not a valid IP", + cepp->ce_fileptr->cf_filename, cepp->ce_varlinenum, + cepp->ce_vardata); + errors++; + continue; + } + } + } + } + } else if (!strcmp(cep->ce_varname, "dns")) { for (cepp = cep->ce_entries; cepp; cepp = cepp->ce_next) { CheckNull(cepp);