2 protocol_subnet.c -- handle the meta-protocol, subnets
3 Copyright (C) 1999-2003 Ivo Timmermans <ivo@o2w.nl>,
4 2000-2003 Guus Sliepen <guus@sliepen.eu.org>
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.1.4.16 2003/11/10 22:31:53 guus Exp $
26 #include "connection.h"
36 bool send_add_subnet(connection_t *c, const subnet_t *subnet)
43 x = send_request(c, "%d %lx %s %s", ADD_SUBNET, random(),
44 subnet->owner->name, netstr = net2str(subnet));
51 bool add_subnet_h(connection_t *c)
53 char subnetstr[MAX_STRING_SIZE];
54 char name[MAX_STRING_SIZE];
60 if(sscanf(c->buffer, "%*d %*x " MAX_STRING " " MAX_STRING, name, subnetstr) != 2) {
61 logger(LOG_ERR, _("Got bad %s from %s (%s)"), "ADD_SUBNET", c->name,
66 /* Check if owner name is a valid */
69 logger(LOG_ERR, _("Got bad %s from %s (%s): %s"), "ADD_SUBNET", c->name,
70 c->hostname, _("invalid name"));
74 /* Check if subnet string is valid */
76 s = str2net(subnetstr);
79 logger(LOG_ERR, _("Got bad %s from %s (%s): %s"), "ADD_SUBNET", c->name,
80 c->hostname, _("invalid subnet string"));
84 if(seen_request(c->buffer))
87 /* Check if the owner of the new subnet is in the connection list */
89 owner = lookup_node(name);
93 owner->name = xstrdup(name);
97 if(c->status.opaque && owner != myself && owner != c->node)
100 /* Check if we already know this subnet */
102 if(lookup_subnet(owner, s)) {
107 /* If we don't know this subnet, but we are the owner, retaliate with a DEL_SUBNET */
109 if(owner == myself) {
110 ifdebug(PROTOCOL) logger(LOG_WARNING, _("Got %s from %s (%s) for ourself"),
111 "ADD_SUBNET", c->name, c->hostname);
113 send_del_subnet(c, s);
117 /* If everything is correct, add the subnet to the list of the owner */
119 subnet_add(owner, s);
123 if(!c->status.opaque)
129 bool send_del_subnet(connection_t *c, const subnet_t *s)
138 x = send_request(c, "%d %lx %s %s", DEL_SUBNET, random(), s->owner->name, netstr);
145 bool del_subnet_h(connection_t *c)
147 char subnetstr[MAX_STRING_SIZE];
148 char name[MAX_STRING_SIZE];
154 if(sscanf(c->buffer, "%*d %*x " MAX_STRING " " MAX_STRING, name, subnetstr) != 2) {
155 logger(LOG_ERR, _("Got bad %s from %s (%s)"), "DEL_SUBNET", c->name,
160 /* Check if owner name is a valid */
162 if(!check_id(name)) {
163 logger(LOG_ERR, _("Got bad %s from %s (%s): %s"), "DEL_SUBNET", c->name,
164 c->hostname, _("invalid name"));
168 /* Check if the owner of the new subnet is in the connection list */
170 owner = lookup_node(name);
173 ifdebug(PROTOCOL) logger(LOG_WARNING, _("Got %s from %s (%s) for %s which is not in our node tree"),
174 "DEL_SUBNET", c->name, c->hostname, name);
178 if(c->status.opaque && owner != myself && owner != c->node)
181 /* Check if subnet string is valid */
183 s = str2net(subnetstr);
186 logger(LOG_ERR, _("Got bad %s from %s (%s): %s"), "DEL_SUBNET", c->name,
187 c->hostname, _("invalid subnet string"));
191 if(seen_request(c->buffer))
194 /* If everything is correct, delete the subnet from the list of the owner */
198 find = lookup_subnet(owner, s);
203 ifdebug(PROTOCOL) logger(LOG_WARNING, _("Got %s from %s (%s) for %s which does not appear in his subnet tree"),
204 "DEL_SUBNET", c->name, c->hostname, name);
208 /* If we are the owner of this subnet, retaliate with an ADD_SUBNET */
210 if(owner == myself) {
211 ifdebug(PROTOCOL) logger(LOG_WARNING, _("Got %s from %s (%s) for ourself"),
212 "DEL_SUBNET", c->name, c->hostname);
213 send_add_subnet(c, find);
219 if(!c->status.opaque)
222 /* Finally, delete it. */
224 subnet_del(owner, find);