tree connection_eval (string name, string session, string s) { // cout << "Evaluating " << name << ", " << session << ", " << s << LF; connection con= connection_get (name, session); if (is_nil (con)) return ""; connection_write (name, session, s); return connection_retrieve (name, session); }
int packet_new(struct packet_pool* pool, struct pcap_pkthdr* header, const unsigned char* data) { struct packet* ret = NULL; pthread_mutex_lock(&pool->free_lock); struct list_element_t* e = list_pop_front(pool->free_list); pthread_mutex_unlock(&pool->free_lock); pool->packets_seen++; if (!(pool->packets_seen % 1000000)) { msg(MSG_STATS, "Seen: %llu, Used: %llu, Free: %llu", pool->packets_seen, pool->used_list->size, pool->free_list->size); } if (!e) { pool->packets_lost++; return -1; } ret = e->data; memcpy(&ret->header, header, sizeof(*header)); memcpy(ret->data, data, header->caplen); uint16_t et = ntohs(ETHERNET(data)->ether_type); if (!(et == ETHERTYPE_IP || et == ETHERTYPE_IPV6 || et == ETHERTYPE_VLAN)) { ret->is_ip = ret->is_ip6 = 0; ret->ip = NULL; ret->ip6 = NULL; } uint8_t offset = et == ETHERTYPE_VLAN?4:0; // ethernetheader is shifted by four bytes if vlan is available // we don't know whether we received ip or ipv6. So lets try: if ((IP(data + offset))->ip_v == 4 || et == ETHERTYPE_IP) { ret->is_ip6 = 0; ret->is_ip = 1; ret->ip = IP(ret->data); ret->ip6 = NULL; //msg(MSG_ERROR, "Found IPv4 packet"); } else if ((IP(data + offset))->ip_v == 6 || et == ETHERTYPE_IPV6) { ret->is_ip6 = 1; ret->is_ip = 0; ret->ip = NULL; ret->ip6 = IP6(ret->data); } else { //msg(MSG_ERROR, "Well. Something is weird here!: Ethertype: %d, IP vesrsion: %d", et, (IP(data + offset))->ip_v); } // only handle packets if its connection is still active ret->connection = connection_get(ret); // TODO: we should discard the packet earlier, at best before copying the packet content if (ret->connection && ret->connection->active) { pthread_mutex_lock(&pool->used_lock); list_push_back(pool->used_list, e); pthread_mutex_unlock(&pool->used_lock); } else { packet_free(pool, ret); } return 0; }
/* * Return 0 on success, if return -1 means the pkt * is unsupported(arp and ipv6) and will be sent later */ static int packet_enqueue(CompareState *s, int mode, Connection **con) { ConnectionKey key; Packet *pkt = NULL; Connection *conn; if (mode == PRIMARY_IN) { pkt = packet_new(s->pri_rs.buf, s->pri_rs.packet_len, s->pri_rs.vnet_hdr_len); } else { pkt = packet_new(s->sec_rs.buf, s->sec_rs.packet_len, s->sec_rs.vnet_hdr_len); } if (parse_packet_early(pkt)) { packet_destroy(pkt, NULL); pkt = NULL; return -1; } fill_connection_key(pkt, &key); conn = connection_get(s->connection_track_table, &key, &s->conn_list); if (!conn->processing) { g_queue_push_tail(&s->conn_list, conn); conn->processing = true; } if (mode == PRIMARY_IN) { if (!colo_insert_packet(&conn->primary_list, pkt)) { error_report("colo compare primary queue size too big," "drop packet"); } } else { if (!colo_insert_packet(&conn->secondary_list, pkt)) { error_report("colo compare secondary queue size too big," "drop packet"); } } *con = conn; return 0; }
gboolean user_new (gchar * line, gpointer data) { gchar * user; gchar * password; gchar * password_repeated; gchar * description; gchar ** splited_string; if (!connection_get ()) { g_print ("Not connected to a kernel server\n"); return FALSE; } // Get user name and password splited_string = g_strsplit (line, " ", 3); if (splited_string[2] == NULL) { user = readline ("Enter new user name: "); }else user = g_strstrip (splited_string[2]); password = readline ("Enter new user password: "******"Reenter the password: "******"Passwords didn't match.. add user failed\n"); return FALSE; } description = readline ("Enter new user description: "); // Create user if (!aos_kernel_user_new (user, password, description, user_new_process, NULL)) { g_print ("Unable to create user\n"); return FALSE; } user_process_var = FALSE; while (user_process_var == FALSE) { sleep (1); printf ("."); } return TRUE; }
gboolean user_list (gchar * line, gpointer data) { if (!connection_get ()) { g_print ("Not connected to a kernel server\n"); return FALSE; } if (!aos_kernel_user_list (0, 0, user_list_process, NULL)) { g_print ("Unable to list already created users\n"); return FALSE; } user_process_var = FALSE; while (user_process_var == FALSE) sleep (1); return TRUE; }
gboolean user_remove (gchar * line, gpointer data) { gchar * user_id; gchar * aux_string; gchar ** splited_string; gint id; // Are we connected ? if (!connection_get ()) { g_print ("Not connected to a kernel server\n"); return FALSE; } // Get user is to remove splited_string = g_strsplit (line, " ", 3); if (splited_string[2] == NULL) { user_id = readline ("Enter user id to remove (listed by 'list user' command): "); }else user_id = g_strstrip (splited_string[2]); id = strtol (user_id, &aux_string, 10); if (strlen (aux_string)) { g_print ("Invalid user id..user del failed.\n"); return FALSE; } if (!aos_kernel_user_remove (id, user_remove_process, NULL)) { g_print ("Unable to remove user\n"); return FALSE; } user_process_var = FALSE; while (user_process_var == FALSE) sleep (1); return TRUE; }