Code beautification, start of multicast support.
This commit is contained in:
parent
354b7ab20e
commit
5a1406adef
9 changed files with 365 additions and 278 deletions
|
|
@ -17,7 +17,7 @@
|
|||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
$Id: protocol_subnet.c,v 1.1.4.17 2003/11/17 15:30:18 guus Exp $
|
||||
$Id: protocol_subnet.c,v 1.1.4.18 2003/12/12 19:52:25 guus Exp $
|
||||
*/
|
||||
|
||||
#include "system.h"
|
||||
|
|
@ -35,17 +35,14 @@
|
|||
|
||||
bool send_add_subnet(connection_t *c, const subnet_t *subnet)
|
||||
{
|
||||
bool x;
|
||||
char *netstr;
|
||||
char netstr[MAXNETSTR];
|
||||
|
||||
cp();
|
||||
|
||||
x = send_request(c, "%d %lx %s %s", ADD_SUBNET, random(),
|
||||
subnet->owner->name, netstr = net2str(subnet));
|
||||
if(!net2str(netstr, sizeof netstr, subnet))
|
||||
return false;
|
||||
|
||||
free(netstr);
|
||||
|
||||
return x;
|
||||
return send_request(c, "%d %lx %s %s", ADD_SUBNET, random(), subnet->owner->name, netstr);
|
||||
}
|
||||
|
||||
bool add_subnet_h(connection_t *c)
|
||||
|
|
@ -53,7 +50,7 @@ bool add_subnet_h(connection_t *c)
|
|||
char subnetstr[MAX_STRING_SIZE];
|
||||
char name[MAX_STRING_SIZE];
|
||||
node_t *owner;
|
||||
subnet_t *s;
|
||||
subnet_t s = {0}, *new;
|
||||
|
||||
cp();
|
||||
|
||||
|
|
@ -73,9 +70,7 @@ bool add_subnet_h(connection_t *c)
|
|||
|
||||
/* Check if subnet string is valid */
|
||||
|
||||
s = str2net(subnetstr);
|
||||
|
||||
if(!s) {
|
||||
if(!str2net(&s, subnetstr)) {
|
||||
logger(LOG_ERR, _("Got bad %s from %s (%s): %s"), "ADD_SUBNET", c->name,
|
||||
c->hostname, _("invalid subnet string"));
|
||||
return false;
|
||||
|
|
@ -99,18 +94,16 @@ bool add_subnet_h(connection_t *c)
|
|||
|
||||
/* Check if we already know this subnet */
|
||||
|
||||
if(lookup_subnet(owner, s)) {
|
||||
free_subnet(s);
|
||||
if(lookup_subnet(owner, &s))
|
||||
return true;
|
||||
}
|
||||
|
||||
/* If we don't know this subnet, but we are the owner, retaliate with a DEL_SUBNET */
|
||||
|
||||
if(owner == myself) {
|
||||
ifdebug(PROTOCOL) logger(LOG_WARNING, _("Got %s from %s (%s) for ourself"),
|
||||
"ADD_SUBNET", c->name, c->hostname);
|
||||
s->owner = myself;
|
||||
send_del_subnet(c, s);
|
||||
s.owner = myself;
|
||||
send_del_subnet(c, &s);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -124,7 +117,7 @@ bool add_subnet_h(connection_t *c)
|
|||
if(!get_config_subnet(cfg, &allowed))
|
||||
return false;
|
||||
|
||||
if(!subnet_compare(s, allowed))
|
||||
if(!subnet_compare(&s, allowed))
|
||||
break;
|
||||
|
||||
free_subnet(allowed);
|
||||
|
|
@ -138,7 +131,8 @@ bool add_subnet_h(connection_t *c)
|
|||
|
||||
/* If everything is correct, add the subnet to the list of the owner */
|
||||
|
||||
subnet_add(owner, s);
|
||||
*(new = new_subnet()) = s;
|
||||
subnet_add(owner, new);
|
||||
|
||||
/* Tell the rest */
|
||||
|
||||
|
|
@ -150,18 +144,14 @@ bool add_subnet_h(connection_t *c)
|
|||
|
||||
bool send_del_subnet(connection_t *c, const subnet_t *s)
|
||||
{
|
||||
bool x;
|
||||
char *netstr;
|
||||
char netstr[MAXNETSTR];
|
||||
|
||||
cp();
|
||||
|
||||
netstr = net2str(s);
|
||||
if(!net2str(netstr, sizeof netstr, s))
|
||||
return false;
|
||||
|
||||
x = send_request(c, "%d %lx %s %s", DEL_SUBNET, random(), s->owner->name, netstr);
|
||||
|
||||
free(netstr);
|
||||
|
||||
return x;
|
||||
return send_request(c, "%d %lx %s %s", DEL_SUBNET, random(), s->owner->name, netstr);
|
||||
}
|
||||
|
||||
bool del_subnet_h(connection_t *c)
|
||||
|
|
@ -169,7 +159,7 @@ bool del_subnet_h(connection_t *c)
|
|||
char subnetstr[MAX_STRING_SIZE];
|
||||
char name[MAX_STRING_SIZE];
|
||||
node_t *owner;
|
||||
subnet_t *s, *find;
|
||||
subnet_t s = {0}, *find;
|
||||
|
||||
cp();
|
||||
|
||||
|
|
@ -202,9 +192,7 @@ bool del_subnet_h(connection_t *c)
|
|||
|
||||
/* Check if subnet string is valid */
|
||||
|
||||
s = str2net(subnetstr);
|
||||
|
||||
if(!s) {
|
||||
if(!str2net(&s, subnetstr)) {
|
||||
logger(LOG_ERR, _("Got bad %s from %s (%s): %s"), "DEL_SUBNET", c->name,
|
||||
c->hostname, _("invalid subnet string"));
|
||||
return false;
|
||||
|
|
@ -215,11 +203,9 @@ bool del_subnet_h(connection_t *c)
|
|||
|
||||
/* If everything is correct, delete the subnet from the list of the owner */
|
||||
|
||||
s->owner = owner;
|
||||
s.owner = owner;
|
||||
|
||||
find = lookup_subnet(owner, s);
|
||||
|
||||
free_subnet(s);
|
||||
find = lookup_subnet(owner, &s);
|
||||
|
||||
if(!find) {
|
||||
ifdebug(PROTOCOL) logger(LOG_WARNING, _("Got %s from %s (%s) for %s which does not appear in his subnet tree"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue