static int execute_set_action(struct sk_buff *skb, const struct nlattr *nested_attr) { int err = 0; switch (nla_type(nested_attr)) { case OVS_KEY_ATTR_PRIORITY: skb->priority = nla_get_u32(nested_attr); break; case OVS_KEY_ATTR_ETHERNET: err = set_eth_addr(skb, nla_data(nested_attr)); break; case OVS_KEY_ATTR_IPV4: err = set_ipv4(skb, nla_data(nested_attr)); break; case OVS_KEY_ATTR_TCP: err = set_tcp(skb, nla_data(nested_attr)); break; case OVS_KEY_ATTR_UDP: err = set_udp(skb, nla_data(nested_attr)); break; } return err; }
static int execute_set_action(struct sk_buff *skb, const struct nlattr *nested_attr, struct ovs_key_ipv4_tunnel *tun_key) { int err = 0; switch (nla_type(nested_attr)) { case OVS_KEY_ATTR_PRIORITY: skb->priority = nla_get_u32(nested_attr); break; case OVS_KEY_ATTR_TUN_ID: /* If we're only using the TUN_ID action, store the value in a * temporary instance of struct ovs_key_ipv4_tunnel on the stack. * If both IPV4_TUNNEL and TUN_ID are being used together we * can't write into the IPV4_TUNNEL action, so make a copy and * write into that version. */ if (!OVS_CB(skb)->tun_key) memset(tun_key, 0, sizeof(*tun_key)); else if (OVS_CB(skb)->tun_key != tun_key) memcpy(tun_key, OVS_CB(skb)->tun_key, sizeof(*tun_key)); OVS_CB(skb)->tun_key = tun_key; OVS_CB(skb)->tun_key->tun_id = nla_get_be64(nested_attr); break; case OVS_KEY_ATTR_IPV4_TUNNEL: OVS_CB(skb)->tun_key = nla_data(nested_attr); break; case OVS_KEY_ATTR_ETHERNET: err = set_eth_addr(skb, nla_data(nested_attr)); break; case OVS_KEY_ATTR_IPV4: err = set_ipv4(skb, nla_data(nested_attr)); break; case OVS_KEY_ATTR_TCP: err = set_tcp(skb, nla_data(nested_attr)); break; case OVS_KEY_ATTR_UDP: err = set_udp(skb, nla_data(nested_attr)); break; } return err; }
static int execute_set_action(struct sk_buff *skb, const struct nlattr *nested_attr, struct ovs_key_ipv4_tunnel *tun_key) { int err = 0; switch (nla_type(nested_attr)) { case OVS_KEY_ATTR_PRIORITY: skb->priority = nla_get_u32(nested_attr); break; case OVS_KEY_ATTR_TUN_ID: if (!OVS_CB(skb)->tun_key) { /* If tun_key is NULL for this skb, assign it to * a value the caller passed in for action processing * and output. This can disappear once we drop support * for setting tun_id outside of tun_key. */ memset(tun_key, 0, sizeof(struct ovs_key_ipv4_tunnel)); OVS_CB(skb)->tun_key = tun_key; } OVS_CB(skb)->tun_key->tun_id = nla_get_be64(nested_attr); OVS_CB(skb)->tun_key->tun_flags |= OVS_FLOW_TNL_F_KEY; break; case OVS_KEY_ATTR_IPV4_TUNNEL: OVS_CB(skb)->tun_key = nla_data(nested_attr); break; case OVS_KEY_ATTR_ETHERNET: err = set_eth_addr(skb, nla_data(nested_attr)); break; case OVS_KEY_ATTR_IPV4: err = set_ipv4(skb, nla_data(nested_attr)); break; case OVS_KEY_ATTR_TCP: err = set_tcp(skb, nla_data(nested_attr)); break; case OVS_KEY_ATTR_UDP: err = set_udp(skb, nla_data(nested_attr)); break; } return err; }
int main(int argc, const char * argv[]) { FILE *text_input; FILE *pcap_out = NULL; // Command-line arguments if(argc != 3){ // Check for more than two arguments, error. system("clear"); fprintf(stderr, "Error running %s: %s\n", argv[0], strerror(errno)); usage_error (*argv); return 7; // Argument List too Long. } // Open files as a data stream text_input = fopen(argv[1], "rb"); pcap_out = fopen(argv[2], "w+b"); // Writeable so we can use it if good. if(argc == 3){ // Check both files to validate they are there and accessable. if (!text_input){ printf("Error! No text file at '%s'.\n", argv[1]); usage_error (*argv); exit_clean(pcap_out, text_input); } else if (!pcap_out){ printf("Error! No destination PCAP file at '%s'\n", argv[2]); usage_error (*argv); exit_clean(pcap_out, text_input); } } printf("DEBUG: Your two file locations are good.\nWho knows if they are the correct types of files. Here...We....GO...\n\n"); struct global global; struct packet packet; struct ethernet ethernet; struct IPv4 IPv4; struct UDP UDP; set_global(&global); set_packet(&packet); set_ethernet(ðernet); set_IPv4(&IPv4); set_udp(&UDP); // Could not get this working. Supposed to loop the writing. // void *structures[5] = { &global, &packet, ðernet, &IPv4, &UDP }; // for (int i = 0; i < 6; i++){ // fwrite(structures[i], sizeof(*structures[i]), 1, pcap_out); // } fwrite(&global, sizeof(global), 1, pcap_out); fwrite(&packet, sizeof(packet), 1, pcap_out); fwrite(ðernet, sizeof(ethernet), 1, pcap_out); fwrite(&IPv4, sizeof(IPv4), 1, pcap_out); fwrite(&UDP, sizeof(UDP), 1, pcap_out); // union type_seq_ver med_tsv; struct med_head med_head; struct status status; struct cmnd cmnd; // READ AND PROCESS the given text file. // 0 is the mead_head. This will tell find_word what the next task is int next_section; next_section = 0; int next_word = 0; // int section = -3; while(!feof(text_input)){ // start with med_head find_word(&next_section, &next_word, text_input); check_set_value(&next_section, &next_word, text_input, pcap_out, argv, &med_head, &status, &cmnd); // Get values for med_head. // 0-5 are for Type, Version, Sequence, From, and To respectively } fclose(pcap_out); fclose(text_input); return 0; }