+ /* Sort on size of subnet mask (IPv4 only at the moment!)
+
+ Three cases: cl->subnets = NULL -> just add this subnet
+ insert before first -> add it in front of list
+ rest: insert after another subnet
+ */
+
+ if(cl->subnets)
+ {
+ p = q = cl->subnets;
+
+ for(; p; p = p->next)
+ {
+ if(subnet->net.ipv4.mask >= p->net.ipv4.mask)
+ break;
+
+ q = p;
+ }
+ }
+
+ if(!cl->subnets || p == cl->subnets) /* First two cases */
+ {
+ /* Insert in front */
+ subnet->next = cl->subnets;
+ subnet->prev = NULL;
+ cl->subnets = subnet;
+ }
+ else /* Third case */
+ {
+ /* Insert after q */
+ subnet->next = q->next;
+ subnet->prev = q;
+ q->next = subnet;
+ }
+
+ if(subnet->next)
+ subnet->next->prev = subnet;