+
+ /* And now add it to the global subnet list (sorted) */
+
+ /* Sort on size of subnet mask (IPv4 only at the moment!)
+
+ Three cases: subnet_list[] = NULL -> just add this subnet
+ insert before first -> add it in front of list
+ rest: insert after another subnet
+ */
+cp
+ if(subnet_list[subnet->type])
+ {
+ p = q = subnet_list[subnet->type];
+
+ for(; p; p = p->global_next)
+ {
+ if(subnet->net.ipv4.mask >= p->net.ipv4.mask)
+ break;
+
+ q = p;
+ }
+ }
+cp
+ if(p == subnet_list[subnet->type]) /* First two cases */
+ {
+ /* Insert in front */
+ subnet->global_next = subnet_list[subnet->type];
+ subnet->global_prev = NULL;
+ subnet_list[subnet->type] = subnet;
+ }
+ else /* Third case */
+ {
+ /* Insert after q */
+ subnet->global_next = q->global_next;
+ subnet->global_prev = q;
+ q->global_next = subnet;
+ }
+cp
+ if(subnet->global_next)
+ subnet->global_next->global_prev = subnet;