2 protocol_subnet.c -- handle the meta-protocol, subnets
3 Copyright (C) 1999-2002 Ivo Timmermans <itimmermans@bigfoot.com>,
4 2000-2002 Guus Sliepen <guus@sliepen.warande.net>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 $Id: protocol_subnet.c,v 1.2 2002/04/09 15:26:01 zarq Exp $
41 #include "connection.h"
48 int send_add_subnet(connection_t *c, subnet_t *subnet)
53 x = send_request(c, "%d %lx %s %s", ADD_SUBNET, random(),
54 subnet->owner->name, netstr = net2str(subnet));
60 int add_subnet_h(connection_t *c)
62 char subnetstr[MAX_STRING_SIZE];
63 char name[MAX_STRING_SIZE];
69 if(sscanf(c->buffer, "%*d %*x "MAX_STRING" "MAX_STRING, name, subnetstr) != 2)
71 syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "ADD_SUBNET", c->name, c->hostname);
75 /* Check if owner name is a valid */
79 syslog(LOG_ERR, _("Got bad %s from %s (%s): %s"), "ADD_SUBNET", c->name, c->hostname, _("invalid name"));
83 /* Check if subnet string is valid */
85 if(!(s = str2net(subnetstr)))
87 syslog(LOG_ERR, _("Got bad %s from %s (%s): %s"), "ADD_SUBNET", c->name, c->hostname, _("invalid subnet string"));
91 if(seen_request(c->buffer))
94 /* Check if the owner of the new subnet is in the connection list */
96 owner = lookup_node(name);
101 owner->name = xstrdup(name);
105 /* Check if we already know this subnet */
107 if(lookup_subnet(owner, s))
113 /* If we don't know this subnet, but we are the owner, retaliate with a DEL_SUBNET */
117 if(debug_lvl >= DEBUG_PROTOCOL)
118 syslog(LOG_WARNING, _("Got %s from %s (%s) for ourself"), "ADD_SUBNET", c->name, c->hostname);
120 send_del_subnet(c, s);
124 /* If everything is correct, add the subnet to the list of the owner */
126 subnet_add(owner, s);
130 for(node = connection_tree->head; node; node = node->next)
132 other = (connection_t *)node->data;
133 if(other->status.active && other != c)
134 send_request(other, "%s", c->buffer);
140 int send_del_subnet(connection_t *c, subnet_t *s)
146 x = send_request(c, "%d %lx %s %s", DEL_SUBNET, random(), s->owner->name, netstr);
152 int del_subnet_h(connection_t *c)
154 char subnetstr[MAX_STRING_SIZE];
155 char name[MAX_STRING_SIZE];
161 if(sscanf(c->buffer, "%*d %*x "MAX_STRING" "MAX_STRING, name, subnetstr) != 2)
163 syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "DEL_SUBNET", c->name, c->hostname);
167 /* Check if owner name is a valid */
171 syslog(LOG_ERR, _("Got bad %s from %s (%s): %s"), "DEL_SUBNET", c->name, c->hostname, _("invalid name"));
175 /* Check if the owner of the new subnet is in the connection list */
177 if(!(owner = lookup_node(name)))
179 if(debug_lvl >= DEBUG_PROTOCOL)
180 syslog(LOG_WARNING, _("Got %s from %s (%s) for %s which is not in our node tree"),
181 "DEL_SUBNET", c->name, c->hostname, name);
185 /* Check if subnet string is valid */
187 if(!(s = str2net(subnetstr)))
189 syslog(LOG_ERR, _("Got bad %s from %s (%s): %s"), "DEL_SUBNET", c->name, c->hostname, _("invalid subnet string"));
193 if(seen_request(c->buffer))
196 /* If everything is correct, delete the subnet from the list of the owner */
200 find = lookup_subnet(owner, s);
206 if(debug_lvl >= DEBUG_PROTOCOL)
207 syslog(LOG_WARNING, _("Got %s from %s (%s) for %s which does not appear in his subnet tree"),
208 "DEL_SUBNET", c->name, c->hostname, name);
212 /* If we are the owner of this subnet, retaliate with an ADD_SUBNET */
216 if(debug_lvl >= DEBUG_PROTOCOL)
217 syslog(LOG_WARNING, _("Got %s from %s (%s) for ourself"), "DEL_SUBNET", c->name, c->hostname);
218 send_add_subnet(c, find);
224 for(node = connection_tree->head; node; node = node->next)
226 other = (connection_t *)node->data;
227 if(other->status.active && other != c)
228 send_request(other, "%s", c->buffer);
231 /* Finally, delete it. */
233 subnet_del(owner, find);