+ char *subnetstr;
+ char *name;
+ conn_list_t *owner;
+ subnet_t *subnet, *old;
+cp
+ if(sscanf(cl->buffer, "%*d %as %as", &name, &subnetstr) != 3)
+ {
+ syslog(LOG_ERR, _("Got bad ADD_SUBNET from %s (%s)"), cl->name, cl->hostname);
+ free(name); free(subnetstr);
+ return -1;
+ }
+
+ /* Check if owner name is a valid */
+
+ if(!check_id(name))
+ {
+ syslog(LOG_ERR, _("Got bad ADD_SUBNET from %s (%s): invalid identity name"), cl->name, cl->hostname);
+ free(name); free(subnetstr);
+ return -1;
+ }
+
+ /* Check if subnet string is valid */
+
+ if((subnet = str2net(subnetstr)) == -1)
+ {
+ syslog(LOG_ERR, _("Got bad ADD_SUBNET from %s (%s): invalid subnet string"), cl->name, cl->hostname);
+ free(name); free(subnetstr);
+ return -1;
+ }
+
+ free(subnetstr);
+
+ /* Check if somebody tries to add a subnet of ourself */
+
+ if(!strcmp(name, myself->name))
+ {
+ syslog(LOG_ERR, _("Warning: got ADD_SUBNET from %s (%s) for ourself, restarting"),
+ cl->name, cl->hostname);
+ free(name);
+ sighup = 1;
+ return 0;
+ }
+
+ /* Check if the owner of the new subnet is in the connection list */
+
+ if(!(owner = lookup_id(name))
+ {
+ syslog(LOG_ERR, _("Got ADD_SUBNET for %s from %s (%s) which is not in our connection list"),
+ name, cl->name, cl->hostname);
+ free(name);
+ return -1;
+ }
+
+ /* If everything is correct, add the subnet to the list of the owner */
+cp
+ return subnet_add(owner, subnet);