void boot(localnode* n) { printf("1\n"); //SockAddr bootAddr; //addr of bootstrap node SockAddr thisaddr_upper; //addr of this node for upper layer access //listen for connections n->addr.port = NODELOCAL_DEFAULT_PORT_ROUTING_LAYER_PEER; n->bootAddr.port = NODELOCAL_DEFAULT_PORT_ROUTING_LAYER_PEER; n->port_upper = NODELOCAL_DEFAULT_PORT_ROUTING_LAYER_UPPER; //get bootstrap node address //getBootstraplocalnodeIp(&bootAddr); if(ipaddr_cmp(&(n->bootAddr.ip), &n->addr.ip)==1 && n->bootAddr.port == n->addr.port) { printf("cmp true, boot = this\n"); //listen on peer port sw_listen(&n->addr); thisaddr_upper = n->addr; thisaddr_upper.port = n->port_upper; //listen on upper port sw_listen(&thisaddr_upper); } else { //connect and save socket fd //n->bsSfd = sw_conn(bootAddr); //sw_listen(&n->addr); //mmm:uncomment it! //n->bootAddr = bootAddr; printf("before join\n"); join(n); } }
oval_result_t oval_ipaddr_cmp(int af, const char *s1, const char *s2, oval_operation_t op) { oval_result_t result = OVAL_RESULT_ERROR; uint32_t mask1 = 0, mask2 = 0; char addr1[INET6_ADDRSTRLEN]; char addr2[INET6_ADDRSTRLEN]; if (ipaddr_parse(af, s1, &mask1, &addr1) || ipaddr_parse(af, s2, &mask2, &addr2)) { return result; } switch (op) { case OVAL_OPERATION_EQUALS: if (!ipaddr_cmp(af, &addr1, &addr2) && mask1 == mask2) result = OVAL_RESULT_TRUE; else result = OVAL_RESULT_FALSE; break; case OVAL_OPERATION_NOT_EQUAL: if (ipaddr_cmp(af, &addr1, &addr2) || mask1 != mask2) result = OVAL_RESULT_TRUE; else result = OVAL_RESULT_FALSE; break; case OVAL_OPERATION_SUBSET_OF: /* This asserts that every IP address in the set of IP addresses * on the system (add2, mask2) must be present in the set of IP * addresses defined in the stated entity (addr1, mask1). */ if (mask1 > mask2) { /* The bigger the netmask (IPv4) or prefix-length (IPv6) is * the less IP addresses there are in the range. */ result = OVAL_RESULT_FALSE; break; } /* Otherwise, compare the first bits defined by mask1 */ ipaddr_mask(af, &addr1, mask1); ipaddr_mask(af, &addr2, mask1); if (ipaddr_cmp(af, &addr1, &addr2) == 0) result = OVAL_RESULT_TRUE; else result = OVAL_RESULT_FALSE; break; case OVAL_OPERATION_GREATER_THAN: ipaddr_mask(af, &addr1, mask1); ipaddr_mask(af, &addr2, mask2); if (ipaddr_cmp(af, &addr1, &addr2) < 0) result = OVAL_RESULT_TRUE; else result = OVAL_RESULT_FALSE; break; case OVAL_OPERATION_GREATER_THAN_OR_EQUAL: ipaddr_mask(af, &addr1, mask1); ipaddr_mask(af, &addr2, mask2); if (ipaddr_cmp(af, &addr1, &addr2) <= 0) result = OVAL_RESULT_TRUE; else result = OVAL_RESULT_FALSE; break; case OVAL_OPERATION_SUPERSET_OF: /* This asserts that every IP address in the set of IP addresses defined in * the stated entity (addr1, mask1) is present in the set of IP addresses * on the system. (addr2, mask2). */ if (mask1 < mask2) { /* The smaller the netmask (IPv4) or prefix-length (IPv6) is * the more IP addresses there are in the range */ result = OVAL_RESULT_FALSE; break; } /* Otherwise, compare the first bits defined by mask2 */ ipaddr_mask(af, &addr1, mask2); ipaddr_mask(af, &addr2, mask2); if (ipaddr_cmp(af, &addr1, &addr2) == 0) result = OVAL_RESULT_TRUE; else result = OVAL_RESULT_FALSE; break; case OVAL_OPERATION_LESS_THAN: ipaddr_mask(af, &addr1, mask1); ipaddr_mask(af, &addr2, mask2); if (ipaddr_cmp(af, &addr1, &addr2) > 0) result = OVAL_RESULT_TRUE; else result = OVAL_RESULT_FALSE; break; case OVAL_OPERATION_LESS_THAN_OR_EQUAL: ipaddr_mask(af, &addr1, mask1); ipaddr_mask(af, &addr2, mask2); if (ipaddr_cmp(af, &addr1, &addr2) >= 0) result = OVAL_RESULT_TRUE; else result = OVAL_RESULT_FALSE; break; default: dE("Unexpected compare operation: %d.\n", op); assert(false); } return result; }