init_users(in_addr_t my_ip, int netbits) #endif { int i; int skip = 0; char newip[16]; int maxusers; in_addr_t netmask = 0; struct in_addr net; struct in_addr ipstart; #ifdef LINUX struct in6_addr next_v6; memcpy(&next_v6, &my_net6, sizeof(my_net6)); ipv6_addr_add(&next_v6, 1); #endif for (i = 0; i < netbits; i++) { netmask = (netmask << 1) | 1; } netmask <<= (32 - netbits); net.s_addr = htonl(netmask); ipstart.s_addr = my_ip & net.s_addr; maxusers = (1 << (32-netbits)) - 3; /* 3: Net addr, broadcast addr, iodined addr */ usercount = MIN(maxusers, USERS); users = calloc(usercount, sizeof(struct user)); for (i = 0; i < usercount; i++) { in_addr_t ip; users[i].id = i; snprintf(newip, sizeof(newip), "0.0.0.%d", i + skip + 1); ip = ipstart.s_addr + inet_addr(newip); if (ip == my_ip && skip == 0) { /* This IP was taken by iodined */ skip++; snprintf(newip, sizeof(newip), "0.0.0.%d", i + skip + 1); ip = ipstart.s_addr + inet_addr(newip); } users[i].tun_ip = ip; net.s_addr = ip; users[i].disabled = 0; users[i].active = 0; #ifdef LINUX ipv6_addr_add(&next_v6, 1); memcpy(&(users[i].tun_ip6), &next_v6, sizeof(struct in6_addr)); #endif /* Rest is reset on login ('V' packet) */ } return usercount; }
void gre_resume(struct tunnel_gre_s *gre, s32 num) { s32 i; s32 use_mtu; s32 use_csum; s32 use_seq; s32 use_key; for (i = 0; i < num; i++) { use_mtu = 0; use_csum = 0; use_seq = 0; use_key = 0; if (!strcmp(gre[i].mtu_disc, "on")) { use_mtu = 1; } if (!strcmp(gre[i].c_sum, "on")) { use_csum = 1; } if (!strcmp(gre[i].seq_syn, "on")) { use_seq = 1; } if (strcmp(gre[i].tunn_key, "empty")) { use_key = atoi(gre[i].tunn_key); } if (ip_gre_add(gre[i].tunn_name, gre[i].src_ip, gre[i].des_ip, use_mtu, use_csum, use_seq, use_key)) { continue; } if (strncmp(gre[i].tunn_ip4, "off", 3) && ipv4_addr_add(gre[i].tunn_name, gre[i].tunn_ip4)) { continue; } if (strncmp(gre[i].tunn_ip6, "off", 3) && ipv6_addr_add(gre[i].tunn_name, gre[i].tunn_ip6)) { continue; } if (if_dev_up(gre[i].tunn_name)) { continue; } } return; }