bool GPRS::join()
{
    char cmd[64];
    char ipAddr[32];
    //Select multiple connection
    //sim900_check_with_cmd("AT+CIPMUX=1\r\n","OK",DEFAULT_TIMEOUT,CMD);

    //set APN
    snprintf(cmd,sizeof(cmd),"AT+CSTT=\"%s\",\"%s\",\"%s\"\r\n",_apn,_userName,_passWord);
    sim900_check_with_cmd(cmd, "OK", DEFAULT_TIMEOUT,CMD);

    //Brings up wireless connection
    sim900_check_with_cmd("AT+CIICR\r\n","OK",DEFAULT_TIMEOUT,CMD);

    //Get local IP address
    sim900_send_cmd("AT+CIFSR\r\n");
    sim900_read_buffer(ipAddr,32,2);

    if(NULL != strstr(ipAddr,"AT+CIFSR")) {
        _ip = str_to_ip(ipAddr+12);
        if(_ip != 0) {
            return true;
        }
    }
    return false;
}
Ejemplo n.º 2
0
void proto_reg_handoff_uasip(void)
{
    static gboolean    prefs_initialized = FALSE;

    if (!prefs_initialized)
    {
        ua_sys_to_term_handle = find_dissector("ua_sys_to_term");
        ua_term_to_sys_handle = find_dissector("ua_term_to_sys");
        prefs_initialized = TRUE;
    }

    use_proxy_ipaddr = FALSE;
    memset(proxy_ipaddr, 0, sizeof(proxy_ipaddr));

    if(uasip_enabled){
        dissector_add_string("media_type", "application/octet-stream", uasip_handle);
    }else{
        dissector_delete_string("media_type", "application/octet-stream", uasip_handle);
    }

    if (strcmp(pref_proxy_ipaddr_s, "") != 0) {
        if (str_to_ip(pref_proxy_ipaddr_s, proxy_ipaddr)) {
            use_proxy_ipaddr = TRUE;
        } else {
            g_warning("uasip: Invalid 'Proxy IP Address': \"%s\"", pref_proxy_ipaddr_s);
        }
    }
}
Ejemplo n.º 3
0
int
main(int argc, char **argv)
{
  struct layer *head,*tcp;
  struct TCPSocket ts;
  struct MAC imac,dmac;
  uint32_t ip,dip,gip;
  uint16_t eport;
  int n;

  if(argc < 6)
	usage(*argv);
  if(if_menu(&imac) < 0)
	exit(1);
  
  str_to_ip(argv[1],&ip);
  str_to_ip(argv[2],&dip);
  str_to_ip(argv[5],&gip);

  if( ARPRequest(&imac,&dmac,ip,gip,5) < 0 ){
	fprintf(stderr,"error: no route to host.\n");
	exit(1);
  }
  ARPReply(&imac,ip,&dmac,gip);
  eport = atoi(argv[4]);	
  createSocket(&ts,&imac,&dmac,ip,dip,atoi(argv[3]),atoi(argv[3]));
  filterDatalink("tcp");
  head = NULL;
  while(!kbhit()){
	if(ts.hostport++ < eport)
	      SYN(&ts);
	if( ( head = recvlayers(&n) ) == NULL)
		continue;		
	if( (tcp = findlayer(head,LT_TCP) ) != NULL ){ 
		struct tcphdr *t;				
		t = (xtcp)tcp->proto;
		if( ( ( t->th_flags & TH_SYN ) == TH_SYN)  && ( ( t->th_flags & TH_ACK ) == TH_ACK) ){
			printf("recv: SYN-ACK from port %d\n",ntohs(t->th_sport));
			printlayers(tcp);
			RST(&ts);			
		}
	}
	rmlayers(head);
  }
  closeDatalink();
  exit(0);
}
//Here is where we ask for APN configuration, with F() so we can save MEMORY
bool GPRS::join(const __FlashStringHelper *apn, const __FlashStringHelper *userName, const __FlashStringHelper *passWord)
{
	byte i;
    char *p, *s;
    char ipAddr[32];
    //Select multiple connection
    //sim900_check_with_cmd("AT+CIPMUX=1\r\n","OK",DEFAULT_TIMEOUT,CMD);

    //set APN. OLD VERSION
    //snprintf(cmd,sizeof(cmd),"AT+CSTT=\"%s\",\"%s\",\"%s\"\r\n",_apn,_userName,_passWord);
    //sim900_check_with_cmd(cmd, "OK\r\n", DEFAULT_TIMEOUT,CMD);
    sim900_send_cmd("AT+CSTT=\"");
    if (apn) {
      sim900_send_cmd(apn);
    }
    sim900_send_cmd("\",\"");
    if (userName) {
      sim900_send_cmd(userName);
    }
    sim900_send_cmd("\",\"");
    if (passWord) {
      sim900_send_cmd(passWord);
    }
    sim900_check_with_cmd("\"\r\n", "OK\r\n", CMD);
    

    //Brings up wireless connection
    sim900_check_with_cmd("AT+CIICR\r\n","OK\r\n", CMD);

    //Get local IP address
    sim900_send_cmd("AT+CIFSR\r\n");
    sim900_clean_buffer(ipAddr,32);
    sim900_read_buffer(ipAddr,32);
	//Response:
	//AT+CIFSR\r\n       -->  8 + 2
	//\r\n				 -->  0 + 2
	//10.160.57.120\r\n  --> 15 + 2 (max)   : TOTAL: 29 
	//Response error:
	//AT+CIFSR\r\n       
	//\r\n				 
	//ERROR\r\n
    if (NULL != strstr(ipAddr,"ERROR")) {
		return false;
	}
    s = ipAddr + 12;
    p = strstr((char *)(s),"\r\n"); //p is last character \r\n
    if (NULL != s) {
        i = 0;
        while (s < p) {
            ip_string[i++] = *(s++);
        }
        ip_string[i] = '\0';            
    }
    _ip = str_to_ip(ip_string);
    if(_ip != 0) {
        return true;
    }
    return false;
} 
Ejemplo n.º 5
0
int
main(int argc, char **argv)
{
 uint32_t ip,rip;
 prog_name = *argv;

 if(argc<3)
	usage();

 if( str_to_ip(argv[1],&ip) == 0){
	fprintf(stderr,"%s: invalid IPv4 address %s\n",prog_name,argv[1]);
 }
	
 if( str_to_ip(argv[2],&rip) == 0){
	fprintf(stderr,"%s: invalid IPv4 address %s\n",prog_name,argv[1]);
 }
 dynaip(ip,rip);	
 exit(0);
}
bool GPRS::queryBearer(uint8_t * bearerStatus)
{
    char receiveBuffer[32];
    char * commaPtr;

    // send AT+SAPBR=2,1 and read "+SAPBR"
    if (sim900_check_with_cmd(F("AT+SAPBR=2,1\r\n"),"+SAPBR:", DATA) == false)
        return false;

    sim900_clean_buffer(receiveBuffer, sizeof(receiveBuffer));

    // check response which looks like:
    // +SAPBR: <cid>,<Status>,<IP_Addr>\r\nOK

    // read cid (always 1)
    if (sim900_read_string_until(receiveBuffer, sizeof(receiveBuffer), "1,") == NULL)
        return false;

    // read until next comma -> status
    commaPtr = sim900_read_string_until(receiveBuffer, sizeof(receiveBuffer), ",");
    if (commaPtr == NULL)
        return false;

    // replace comma with string termination
    *commaPtr = '\0';

    // now extract status
    *bearerStatus = (uint8_t)atol(receiveBuffer);

    // only check for ip address if we are connected (=1)
    if (*bearerStatus == 1)
    {
        char * endOfIpAddress = NULL;

        // read ip address, which is enclosed in '"', so read first '"'
        if (sim900_read_string_until(receiveBuffer, sizeof(receiveBuffer), "\"") == NULL)
            return false;

        // read second '"'
        endOfIpAddress = sim900_read_string_until(receiveBuffer, sizeof(receiveBuffer), "\"");
        if (endOfIpAddress == NULL)
            return false;

        *endOfIpAddress = '\0';

        strncpy(ip_string, receiveBuffer, sizeof(ip_string));
        _ip = str_to_ip(ip_string);
    }

    // flush rest of data which should be "\r\nOK"
    sim900_flush_serial();

    return true;;
}
bool GPRS::gethostbyname(const char* host, uint32_t* ip)
{
    uint32_t addr = str_to_ip(host);
    char buf[17];
    snprintf(buf, sizeof(buf), "%d.%d.%d.%d", (addr>>24)&0xff, (addr>>16)&0xff, (addr>>8)&0xff, addr&0xff);
    if (strcmp(buf, host) == 0) {
        *ip = addr;
        return true;
    }
    return false;
}
Ejemplo n.º 8
0
static void
mkipv4_address( address **addr, const char *str_addr )
{
	int   ret;
	char *addr_data;

	*addr=(address *)g_malloc( sizeof(address) );
	addr_data=(char *)g_malloc( 4 );
	ret = str_to_ip(str_addr, addr_data);
	if (ret)
		SET_ADDRESS(*addr, AT_IPv4, 4, addr_data);
	else
		SET_ADDRESS(*addr, AT_STRINGZ, (int)strlen(ADDR_INVLD)+1, ADDR_INVLD);
}
Ejemplo n.º 9
0
wiced_result_t wiced_hostname_lookup( const char* hostname, wiced_ip_address_t* address, uint32_t timeout_ms )
{
    wiced_assert("Bad args", (hostname != NULL) && (address != NULL));

    WICED_LINK_CHECK( WICED_STA_INTERFACE );

    /* Check if address is a string representation of a IPv4 or IPv6 address i.e. xxx.xxx.xxx.xxx */
    if ( str_to_ip( hostname, address ) == 0 )
    {
        /* yes this is a string representation of a IPv4/6 address */
        return WICED_TCPIP_SUCCESS;
    }

    return dns_client_hostname_lookup( hostname, address, timeout_ms );
}
Ejemplo n.º 10
0
int8_t DNSTimeOut(uint8_t * name, uint8_t * ip_from_dns, uint32_t timeout)
{
	int8_t ret;

    str_to_ip(name, ip_from_dns);
    char buf[17];
    snprintf(buf, sizeof(buf), "%d.%d.%d.%d", ip_from_dns[0], ip_from_dns[1], ip_from_dns[2], ip_from_dns[3]);
    if (strcmp(buf, name) == 0) {
        return 0;
    }

	sockPool *sockP = sockPoolAlloc();
	DNS_init(sockP->sockNo,sockP->netBuf);
	ret = DNS_run(NetInfo.dns,name,ip_from_dns);

	if(ret < 0)
	{
		printf("DNS timeout.\r\n");
	}
	sockPoolFree(sockP);
	return ret;
}
//Here is where we ask for APN configuration, with F() so we can save MEMORY
bool GPRS::join(const __FlashStringHelper *apn, const __FlashStringHelper *userName, const __FlashStringHelper *passWord)

{
    char cmd[64];
    char ipAddr[32];
    //Select multiple connection
    //sim900_check_with_cmd("AT+CIPMUX=1\r\n","OK",DEFAULT_TIMEOUT,CMD);

    //set APN. OLD VERSION
/*    snprintf(cmd,sizeof(cmd),"AT+CSTT=\"%s\",\"%s\",\"%s\"\r\n",_apn,_userName,_passWord);
    sim900_check_with_cmd(cmd, "OK\r\n", DEFAULT_TIMEOUT,CMD);
*/
    sim900_send_cmd("AT+CSTT=\"");
    sim900_send_cmd(apn);
    sim900_send_cmd("\",\"");
    sim900_send_cmd(userName);
    sim900_send_cmd("\",\"");
    sim900_send_cmd(passWord);
    sim900_check_with_cmd("\"\r\n", "OK\r\n", CMD);
    

    //Brings up wireless connection
    sim900_check_with_cmd("AT+CIICR\r\n","OK\r\n", CMD);

    //Get local IP address
    sim900_send_cmd("AT+CIFSR\r\n");
    sim900_clean_buffer(ipAddr,32);
    sim900_read_buffer(ipAddr,32,2);
//Serial.print("ipAddr: ");
//Serial.println(ipAddr);

    if(NULL != strstr(ipAddr,"AT+CIFSR")) {
        _ip = str_to_ip(ipAddr+12);
        if(_ip != 0) {
            return true;
        }
    }
    return false;
} 
Ejemplo n.º 12
0
static void
parse_field_value(struct cls_rule *rule, enum field_index index,
                  const char *value)
{
    uint8_t mac[ETH_ADDR_LEN];
    ovs_be64 tun_id, tun_mask;
    ovs_be32 ip, mask;
    struct in6_addr ipv6, ipv6_mask;
    uint16_t port_no;

    switch (index) {
    case F_TUN_ID:
        str_to_tun_id(value, &tun_id, &tun_mask);
        cls_rule_set_tun_id_masked(rule, tun_id, tun_mask);
        break;

    case F_IN_PORT:
        if (!parse_port_name(value, &port_no)) {
            port_no = atoi(value);
        }
        if (port_no == OFPP_LOCAL) {
            port_no = ODPP_LOCAL;
        }
        cls_rule_set_in_port(rule, port_no);
        break;

    case F_DL_VLAN:
        cls_rule_set_dl_vlan(rule, htons(str_to_u32(value)));
        break;

    case F_DL_VLAN_PCP:
        cls_rule_set_dl_vlan_pcp(rule, str_to_u32(value));
        break;

    case F_DL_SRC:
        str_to_mac(value, mac);
        cls_rule_set_dl_src(rule, mac);
        break;

    case F_DL_DST:
        str_to_mac(value, mac);
        cls_rule_set_dl_dst(rule, mac);
        break;

    case F_DL_TYPE:
        cls_rule_set_dl_type(rule, htons(str_to_u32(value)));
        break;

    case F_NW_SRC:
        str_to_ip(value, &ip, &mask);
        cls_rule_set_nw_src_masked(rule, ip, mask);
        break;

    case F_NW_DST:
        str_to_ip(value, &ip, &mask);
        cls_rule_set_nw_dst_masked(rule, ip, mask);
        break;

    case F_NW_PROTO:
        cls_rule_set_nw_proto(rule, str_to_u32(value));
        break;

    case F_NW_TOS:
        cls_rule_set_nw_tos(rule, str_to_u32(value));
        break;

    case F_TP_SRC:
        cls_rule_set_tp_src(rule, htons(str_to_u32(value)));
        break;

    case F_TP_DST:
        cls_rule_set_tp_dst(rule, htons(str_to_u32(value)));
        break;

    case F_ICMP_TYPE:
        cls_rule_set_icmp_type(rule, str_to_u32(value));
        break;

    case F_ICMP_CODE:
        cls_rule_set_icmp_code(rule, str_to_u32(value));
        break;

    case F_ARP_SHA:
        str_to_mac(value, mac);
        cls_rule_set_arp_sha(rule, mac);
        break;

    case F_ARP_THA:
        str_to_mac(value, mac);
        cls_rule_set_arp_tha(rule, mac);
        break;

    case F_IPV6_SRC:
        str_to_ipv6(value, &ipv6, &ipv6_mask);
        cls_rule_set_ipv6_src_masked(rule, &ipv6, &ipv6_mask);
        break;

    case F_IPV6_DST:
        str_to_ipv6(value, &ipv6, &ipv6_mask);
        cls_rule_set_ipv6_dst_masked(rule, &ipv6, &ipv6_mask);
        break;

    case F_ND_TARGET:
        str_to_ipv6(value, &ipv6, NULL);
        cls_rule_set_nd_target(rule, ipv6);
        break;

    case F_ND_SLL:
        str_to_mac(value, mac);
        cls_rule_set_arp_sha(rule, mac);
        break;

    case F_ND_TLL:
        str_to_mac(value, mac);
        cls_rule_set_arp_tha(rule, mac);
        break;

    case N_FIELDS:
        NOT_REACHED();
    }
}
Ejemplo n.º 13
0
Archivo: ac.c Proyecto: withwave/RT5350
int main(int argc, char *argv[])
{
    int opt;
    char options[] = "abcdefghpqrstuvwz?m:i:j:";
    int fd;
    int method=-1;
    struct ac_args args;


    fd = open("/dev/"AC_DEVNAME, O_RDONLY);
    if (fd < 0)
    {
	printf("Open %s pseudo device failed\n","/dev/"AC_DEVNAME);
	return 0;
    }

    if(argc < 2) {
	show_usage();
	return 0;
    }

    while ((opt = getopt (argc, argv, options)) != -1) {
	switch (opt) {
	case 'a':  
	    method=AC_ADD_MAC_UL_ENTRY;
	    break;
	case 'b':  
	    method=AC_ADD_MAC_DL_ENTRY;
	    break;
	case 'c': 
	    method=AC_DEL_MAC_UL_ENTRY;
	    break;
	case 'd': 
	    method=AC_DEL_MAC_DL_ENTRY;
	    break;
	case 'e': 
	    method=AC_ADD_IP_UL_ENTRY;
	    break;
	case 'f': 
	    method=AC_ADD_IP_DL_ENTRY;
	    break;
	case 'g': 
	    method=AC_DEL_IP_UL_ENTRY;
	    break;
	case 'h': 
	    method=AC_DEL_IP_DL_ENTRY;
	    break;
	case 'p': 
	    method=AC_GET_MAC_UL_PKT_CNT;
	    break;
	case 'q': 
	    method=AC_GET_MAC_DL_PKT_CNT;
	    break;
	case 'r': 
	    method=AC_GET_MAC_UL_BYTE_CNT;
	    break;
	case 's': 
	    method=AC_GET_MAC_DL_BYTE_CNT;
	    break;
	case 't': 
	    method=AC_GET_IP_UL_PKT_CNT;
	    break;
	case 'u': 
	    method=AC_GET_IP_DL_PKT_CNT;
	    break;
	case 'v': 
	    method=AC_GET_IP_UL_BYTE_CNT;
	    break;
	case 'w': 
	    method=AC_GET_IP_DL_BYTE_CNT;
	    break;
	case 'z': /* CleanTbl */
	    method=AC_CLEAN_TBL;
	    break;
	case 'm': /* Mac */
	    str_to_mac(args.mac, optarg);
	    break;
	case 'i': /* IP */
	    str_to_ip(&args.ip_s, optarg);
	    break;
	case 'j':
	    str_to_ip(&args.ip_e, optarg);
	    break;
	case '?': /* Help */
	    show_usage();
	    break;
	}
    } 


    switch(method) {
    case AC_ADD_MAC_UL_ENTRY:
    case AC_ADD_MAC_DL_ENTRY:
    case AC_ADD_IP_UL_ENTRY:
    case AC_ADD_IP_DL_ENTRY:
    case AC_CLEAN_TBL:
	    SetAcEntry(&args, method);
	    if(args.result == AC_TBL_FULL) {
		    printf("Accounting Table Full!!\n");
	    }else {
		    printf("Accounting command ok!\n");
	    }
	    break;
    case AC_DEL_MAC_UL_ENTRY:
    case AC_DEL_MAC_DL_ENTRY:
    case AC_DEL_IP_UL_ENTRY:
    case AC_DEL_IP_DL_ENTRY:
	    SetAcEntry(&args, method);
	    if(args.result == AC_SUCCESS) {
		    printf("Delete Entry ok!\n");
	    }else{
		    printf("Delete Entry fail!\n");
	    }
	    break;
    case AC_GET_MAC_UL_PKT_CNT:
    case AC_GET_MAC_DL_PKT_CNT: 
    case AC_GET_IP_UL_PKT_CNT:
    case AC_GET_IP_DL_PKT_CNT:
    case AC_GET_MAC_UL_BYTE_CNT:
    case AC_GET_MAC_DL_BYTE_CNT:
    case AC_GET_IP_UL_BYTE_CNT: 
    case AC_GET_IP_DL_BYTE_CNT:  
	    GetAcEntry(&args, method);
	    printf("Count=%d\n",args.cnt);
	    break;
    }

    return 0;
}
Ejemplo n.º 14
0
int main(int argc, char *argv[])
{
    int opt;
    char options[] = "abcdefghklnopqryz?m:i:j:t:s:u:v:w";

    int method=-1;
    struct mtr_args args;
    struct mtr_list_args *args2;
    int result = 0;
    int i;

    if(argc < 2) {
	show_usage();
	return 0;
    }

    while ((opt = getopt (argc, argv, options)) != -1) {
	switch (opt) {
	case 'a':  
	    method=MTR_ADD_MAC_UL_ENTRY;
	    break;
	case 'b':  
	    method=MTR_ADD_MAC_DL_ENTRY;
	    break;
	case 'c': 
	    method=MTR_DEL_MAC_UL_ENTRY;
	    break;
	case 'd': 
	    method=MTR_DEL_MAC_DL_ENTRY;
	    break;
	case 'e': 
	    method=MTR_ADD_IP_UL_ENTRY;
	    break;
	case 'f': 
	    method=MTR_ADD_IP_DL_ENTRY;
	    break;
	case 'g': 
	    method=MTR_DEL_IP_UL_ENTRY;
	    break;
	case 'h': 
	    method=MTR_DEL_IP_DL_ENTRY;
	    break;
	case 'k': 
	    method=MTR_ADD_SYN_ENTRY;
	    break;
	case 'l': 
	    method=MTR_ADD_FIN_ENTRY;
	    break;
	case 'n': 
	    method=MTR_ADD_UDP_ENTRY;
	    break;
 	case 'o': 
	    method=MTR_ADD_ICMP_ENTRY;
	    break;
	case 'p': 
	    method=MTR_DEL_SYN_ENTRY;
	    break;
	case 'q': 
	    method=MTR_DEL_FIN_ENTRY;
	    break;
	case 'r': 
	    method=MTR_DEL_UDP_ENTRY;
	    break;
	case 'y': 
	    method=MTR_DEL_ICMP_ENTRY;
	    break;
	case 'z': /* CleanTbl */
	    method=MTR_CLEAN_TBL;
	    break;
	case 'm': /* Mac */
	    str_to_mac(args.mac, optarg);
	    break;
	case 'i': /* IpS */
	    str_to_ip(&args.ip_s, optarg);
	    break;
	case 'j': /* IpE */
	    str_to_ip(&args.ip_e, optarg);
	    break;
	case 't': /* TokenRate */
	    args.token_rate=strtoll(optarg, NULL, 10);
	    break;
	case 's': /* Bucket Size */
	    if(strcasecmp(optarg,"4K")==0){
		args.bk_size=0;
	    }else if(strcasecmp(optarg,"8K")==0){
		args.bk_size=1;
	    }else if(strcasecmp(optarg,"16K")==0){
		args.bk_size=2;
	    }else if(strcasecmp(optarg,"32K")==0){
		args.bk_size=3;
	    }else {
		args.bk_size=strtoll(optarg, NULL, 10);
	    }
	    break;
	case 'u':
	    if(strcasecmp(optarg,"1ms")==0){
		args.mtr_intval=_1MS;
	    }else if(strcasecmp(optarg,"10ms")==0){
		args.mtr_intval=_10MS;
	    }else if(strcasecmp(optarg,"50ms")==0){
		args.mtr_intval=_50MS;
	    }else if(strcasecmp(optarg,"100ms")==0){
		args.mtr_intval=_100MS;
	    }else if(strcasecmp(optarg,"500ms")==0){
		args.mtr_intval=_500MS;
	    }else if(strcasecmp(optarg,"1000ms")==0){
		args.mtr_intval=_1000MS;
	    }else if(strcasecmp(optarg,"5000ms")==0){
		args.mtr_intval=_5000MS;
	    }else if(strcasecmp(optarg,"10000ms")==0){
		args.mtr_intval=_10000MS;
	    }else {
		printf("Error: -u 10ms/50ms/100ms/500ms/1000ms/5000ms/10000ms\n");
		return 0;
	    }
	    break;
	case 'v':
	    if(strcasecmp(optarg,"Byte")==0){
		args.mtr_mode=0;
	    }else if(strcasecmp(optarg,"Pkt")==0){
		args.mtr_mode=1;
	    }else {
		printf("Error: -v Byte/Pkt\n");
		return 0;
	    }
	    break;
	case 'w':
	    method=MTR_GET_ALL_ENTRIES;
	    break;
	case '?': /* Help */
	    show_usage();
	    break;
	}
    } 

    switch(method) 
    {
    case MTR_ADD_MAC_UL_ENTRY:
    case MTR_ADD_MAC_DL_ENTRY:
    case MTR_DEL_MAC_UL_ENTRY:
    case MTR_DEL_MAC_DL_ENTRY:
    case MTR_ADD_IP_UL_ENTRY:
    case MTR_ADD_IP_DL_ENTRY:
    case MTR_DEL_IP_UL_ENTRY:
    case MTR_DEL_IP_DL_ENTRY:
    case MTR_CLEAN_TBL:
    case MTR_ADD_SYN_ENTRY:
    case MTR_ADD_FIN_ENTRY:
    case MTR_ADD_UDP_ENTRY:
    case MTR_ADD_ICMP_ENTRY:
    case MTR_DEL_SYN_ENTRY:
    case MTR_DEL_FIN_ENTRY:
    case MTR_DEL_UDP_ENTRY:
    case MTR_DEL_ICMP_ENTRY:
	    SetMtrEntry(&args, method);
	    result = args.result;
	    break;
    case MTR_GET_ALL_ENTRIES:
	    args2 = malloc(sizeof(struct mtr_list_args) + sizeof(struct mtr_args)*511);
	    MtrGetAllEntries(args2);
	    result = args2->result;
	    printf("Total Entry Count = %d\n", args2->num_of_entries);
	    for(i=0;i<args2->num_of_entries;i++){
		printf("#%d :MAC=%02X:%02X:%02X:%02X:%02X:%02X\n", \
			i, args2->entries[i].mac[0], args2->entries[i].mac[1], args2->entries[i].mac[2], \
			args2->entries[i].mac[3], args2->entries[i].mac[4], args2->entries[i].mac[5]);
		printf("   :SIP %u.%u.%u.%u->%u.%u.%u.%u\n\r", NIPQUAD(args2->entries[i].ip_s), NIPQUAD(args2->entries[i].ip_e));
		printf("   :BucketSize=%d Token_Rate:%d MtrInterval=%d\n", args2->entries[i].bk_size, args2->entries[i].token_rate, args2->entries[i].mtr_intval);
	    }
	    free(args2);
	    break;
    }

    if(result == MTR_TBL_FULL) {
	printf("table full\n");
    }else if(result == MTR_FAIL){
	printf("fail\n");
    }else{
	printf("done\n");
    }

    return 0;
}
Ejemplo n.º 15
0
static void
parse_named_action(enum ofputil_action_code code,
                   char *arg, struct ofpbuf *ofpacts)
{
    struct ofpact_tunnel *tunnel;
    uint16_t vid;
    uint16_t ethertype;
    ovs_be32 ip;
    uint8_t pcp;
    uint8_t tos;

    switch (code) {
    case OFPUTIL_ACTION_INVALID:
        NOT_REACHED();

    case OFPUTIL_OFPAT10_OUTPUT:
    case OFPUTIL_OFPAT11_OUTPUT:
        parse_output(arg, ofpacts);
        break;

    case OFPUTIL_OFPAT10_SET_VLAN_VID:
    case OFPUTIL_OFPAT11_SET_VLAN_VID:
        vid = str_to_u32(arg);
        if (vid & ~VLAN_VID_MASK) {
            ovs_fatal(0, "%s: not a valid VLAN VID", arg);
        }
        ofpact_put_SET_VLAN_VID(ofpacts)->vlan_vid = vid;
        break;

    case OFPUTIL_OFPAT10_SET_VLAN_PCP:
    case OFPUTIL_OFPAT11_SET_VLAN_PCP:
        pcp = str_to_u32(arg);
        if (pcp & ~7) {
            ovs_fatal(0, "%s: not a valid VLAN PCP", arg);
        }
        ofpact_put_SET_VLAN_PCP(ofpacts)->vlan_pcp = pcp;
        break;

    case OFPUTIL_OFPAT12_SET_FIELD:
        set_field_parse(arg, ofpacts);
        break;

    case OFPUTIL_OFPAT10_STRIP_VLAN:
    case OFPUTIL_OFPAT11_POP_VLAN:
        ofpact_put_STRIP_VLAN(ofpacts);
        break;

    case OFPUTIL_OFPAT11_PUSH_VLAN:
        ethertype = str_to_u16(arg, "ethertype");
        if (ethertype != ETH_TYPE_VLAN_8021Q) {
            /* XXX ETH_TYPE_VLAN_8021AD case isn't supported */
            ovs_fatal(0, "%s: not a valid VLAN ethertype", arg);
        }
        ofpact_put_PUSH_VLAN(ofpacts);
        break;

    case OFPUTIL_OFPAT11_SET_QUEUE:
        ofpact_put_SET_QUEUE(ofpacts)->queue_id = str_to_u32(arg);
        break;


    case OFPUTIL_OFPAT10_SET_DL_SRC:
    case OFPUTIL_OFPAT11_SET_DL_SRC:
        str_to_mac(arg, ofpact_put_SET_ETH_SRC(ofpacts)->mac);
        break;

    case OFPUTIL_OFPAT10_SET_DL_DST:
    case OFPUTIL_OFPAT11_SET_DL_DST:
        str_to_mac(arg, ofpact_put_SET_ETH_DST(ofpacts)->mac);
        break;

    case OFPUTIL_OFPAT10_SET_NW_SRC:
    case OFPUTIL_OFPAT11_SET_NW_SRC:
        str_to_ip(arg, &ip);
        ofpact_put_SET_IPV4_SRC(ofpacts)->ipv4 = ip;
        break;

    case OFPUTIL_OFPAT10_SET_NW_DST:
    case OFPUTIL_OFPAT11_SET_NW_DST:
        str_to_ip(arg, &ip);
        ofpact_put_SET_IPV4_DST(ofpacts)->ipv4 = ip;
        break;

    case OFPUTIL_OFPAT10_SET_NW_TOS:
    case OFPUTIL_OFPAT11_SET_NW_TOS:
        tos = str_to_u32(arg);
        if (tos & ~IP_DSCP_MASK) {
            ovs_fatal(0, "%s: not a valid TOS", arg);
        }
        ofpact_put_SET_IPV4_DSCP(ofpacts)->dscp = tos;
        break;

    case OFPUTIL_OFPAT11_DEC_NW_TTL:
        NOT_REACHED();

    case OFPUTIL_OFPAT10_SET_TP_SRC:
    case OFPUTIL_OFPAT11_SET_TP_SRC:
        ofpact_put_SET_L4_SRC_PORT(ofpacts)->port = str_to_u32(arg);
        break;

    case OFPUTIL_OFPAT10_SET_TP_DST:
    case OFPUTIL_OFPAT11_SET_TP_DST:
        ofpact_put_SET_L4_DST_PORT(ofpacts)->port = str_to_u32(arg);
        break;

    case OFPUTIL_OFPAT10_ENQUEUE:
        parse_enqueue(arg, ofpacts);
        break;

    case OFPUTIL_NXAST_RESUBMIT:
        parse_resubmit(arg, ofpacts);
        break;

    case OFPUTIL_NXAST_SET_TUNNEL:
    case OFPUTIL_NXAST_SET_TUNNEL64:
        tunnel = ofpact_put_SET_TUNNEL(ofpacts);
        tunnel->ofpact.compat = code;
        tunnel->tun_id = str_to_u64(arg);
        break;

    case OFPUTIL_NXAST_WRITE_METADATA:
        parse_metadata(ofpacts, arg);
        break;

    case OFPUTIL_NXAST_SET_QUEUE:
        ofpact_put_SET_QUEUE(ofpacts)->queue_id = str_to_u32(arg);
        break;

    case OFPUTIL_NXAST_POP_QUEUE:
        ofpact_put_POP_QUEUE(ofpacts);
        break;

    case OFPUTIL_NXAST_REG_MOVE:
        nxm_parse_reg_move(ofpact_put_REG_MOVE(ofpacts), arg);
        break;

    case OFPUTIL_NXAST_REG_LOAD:
        nxm_parse_reg_load(ofpact_put_REG_LOAD(ofpacts), arg);
        break;

    case OFPUTIL_NXAST_NOTE:
        parse_note(arg, ofpacts);
        break;

    case OFPUTIL_NXAST_MULTIPATH:
        multipath_parse(ofpact_put_MULTIPATH(ofpacts), arg);
        break;

    case OFPUTIL_NXAST_BUNDLE:
        bundle_parse(arg, ofpacts);
        break;

    case OFPUTIL_NXAST_BUNDLE_LOAD:
        bundle_parse_load(arg, ofpacts);
        break;

    case OFPUTIL_NXAST_RESUBMIT_TABLE:
    case OFPUTIL_NXAST_OUTPUT_REG:
    case OFPUTIL_NXAST_DEC_TTL_CNT_IDS:
        NOT_REACHED();

    case OFPUTIL_NXAST_LEARN:
        learn_parse(arg, ofpacts);
        break;

    case OFPUTIL_NXAST_EXIT:
        ofpact_put_EXIT(ofpacts);
        break;

    case OFPUTIL_NXAST_DEC_TTL:
        parse_dec_ttl(ofpacts, arg);
        break;

    case OFPUTIL_NXAST_SET_MPLS_TTL:
    case OFPUTIL_OFPAT11_SET_MPLS_TTL:
        parse_set_mpls_ttl(ofpacts, arg);
        break;

    case OFPUTIL_OFPAT11_DEC_MPLS_TTL:
    case OFPUTIL_NXAST_DEC_MPLS_TTL:
        ofpact_put_DEC_MPLS_TTL(ofpacts);
        break;

    case OFPUTIL_NXAST_FIN_TIMEOUT:
        parse_fin_timeout(ofpacts, arg);
        break;

    case OFPUTIL_NXAST_CONTROLLER:
        parse_controller(ofpacts, arg);
        break;

    case OFPUTIL_OFPAT11_PUSH_MPLS:
    case OFPUTIL_NXAST_PUSH_MPLS:
        ofpact_put_PUSH_MPLS(ofpacts)->ethertype =
            htons(str_to_u16(arg, "push_mpls"));
        break;

    case OFPUTIL_OFPAT11_POP_MPLS:
    case OFPUTIL_NXAST_POP_MPLS:
        ofpact_put_POP_MPLS(ofpacts)->ethertype =
            htons(str_to_u16(arg, "pop_mpls"));
        break;

    case OFPUTIL_NXAST_STACK_PUSH:
        nxm_parse_stack_action(ofpact_put_STACK_PUSH(ofpacts), arg);
        break;
    case OFPUTIL_NXAST_STACK_POP:
        nxm_parse_stack_action(ofpact_put_STACK_POP(ofpacts), arg);
        break;

    case OFPUTIL_NXAST_SAMPLE:
        parse_sample(ofpacts, arg);
        break;
    }
}
Ejemplo n.º 16
0
/*
 * RFC2428 states...
 *
 *     AF Number   Protocol
 *     ---------   --------
 *     1           Internet Protocol, Version 4
 *     2           Internet Protocol, Version 6
 *
 *     AF Number   Address Format      Example
 *     ---------   --------------      -------
 *     1           dotted decimal      132.235.1.2
 *     2           IPv6 string         1080::8:800:200C:417A
 *                 representations
 *                 defined in
 *
 *     The following are sample EPRT commands:
 *          EPRT |1|132.235.1.2|6275|
 *          EPRT |2|1080::8:800:200C:417A|5282|
 *
 *     The first command specifies that the server should use IPv4 to open a
 *     data connection to the host "132.235.1.2" on TCP port 6275.  The
 *     second command specifies that the server should use the IPv6 network
 *     protocol and the network address "1080::8:800:200C:417A" to open a
 *     TCP data connection on port 5282.
 *
 * ... which means in fact that RFC2428 is capable to handle both,
 * IPv4 and IPv6 so we have to care about the address family and properly
 * act depending on it.
 *
 */
static gboolean
parse_eprt_request(const guchar* line, gint linelen, guint32 *eprt_af,
        guint32 *eprt_ip, guint16 *eprt_ipv6, guint16 *ftp_port,
        guint32 *eprt_ip_len, guint32 *ftp_port_len)
{
    gint      delimiters_seen = 0;
    gchar     delimiter;
    gint      fieldlen;
    gchar    *field;
    gint      n;
    gint      lastn;
    char     *args, *p;
    gboolean  ret = TRUE;


    /* line contains the EPRT parameters, we need at least the 4 delimiters */
    if (!line || linelen<4)
        return FALSE;

    /* Copy the rest of the line into a null-terminated buffer. */
    args = wmem_strndup(wmem_packet_scope(), line, linelen);
    p = args;
    /*
     * Handle a NUL being in the line; if there's a NUL in the line,
     * strlen(args) will terminate at the NUL and will thus return
     * a value less than linelen.
     */
    if ((gint)strlen(args) < linelen)
        linelen = (gint)strlen(args);

    /*
     * RFC2428 sect. 2 states ...
     *
     *     The EPRT command keyword MUST be followed by a single space (ASCII
     *     32). Following the space, a delimiter character (<d>) MUST be
     *     specified.
     *
     * ... the preceding <space> is already stripped so we know that the first
     * character must be the delimiter and has just to be checked to be valid.
     */
    if (!isvalid_rfc2428_delimiter(*p))
        return FALSE;  /* EPRT command does not follow a vaild delimiter;
                        * malformed EPRT command - immediate escape */

    delimiter = *p;
    /* Validate that the delimiter occurs 4 times in the string */
    for (n = 0; n < linelen; n++) {
        if (*(p+n) == delimiter)
            delimiters_seen++;
    }
    if (delimiters_seen != 4)
        return FALSE; /* delimiter doesn't occur 4 times
                       * probably no EPRT request - immediate escape */

    /* we know that the first character is a delimiter... */
    delimiters_seen = 1;
    lastn = 0;
    /* ... so we can start searching from the 2nd onwards */
    for (n=1; n < linelen; n++) {

        if (*(p+n) != delimiter)
            continue;

        /* we found a delimiter */
        delimiters_seen++;

        fieldlen = n - lastn - 1;
        if (fieldlen<=0)
            return FALSE; /* all fields must have data in them */
        field =  p + lastn + 1;

        if (delimiters_seen == 2) {     /* end of address family field */
            gchar *af_str;
            af_str = wmem_strndup(wmem_packet_scope(), field, fieldlen);
            if (!ws_strtou32(af_str, NULL, eprt_af))
                return FALSE;
        }
        else if (delimiters_seen == 3) {/* end of IP address field */
            gchar *ip_str;
            ip_str = wmem_strndup(wmem_packet_scope(), field, fieldlen);

            if (*eprt_af == EPRT_AF_IPv4) {
                if (str_to_ip(ip_str, eprt_ip))
                   ret = TRUE;
                else
                   ret = FALSE;
            }
            else if (*eprt_af == EPRT_AF_IPv6) {
                if (str_to_ip6(ip_str, eprt_ipv6))
                   ret = TRUE;
                else
                   ret = FALSE;
            }
            else
                return FALSE; /* invalid/unknown address family */

            *eprt_ip_len = fieldlen;
        }
        else if (delimiters_seen == 4) {/* end of port field */
            gchar *pt_str;
            pt_str = wmem_strndup(wmem_packet_scope(), field, fieldlen);

            if (!ws_strtou16(pt_str, NULL, ftp_port))
                return FALSE;
            *ftp_port_len = fieldlen;
        }

        lastn = n;
    }

    return ret;
}
Ejemplo n.º 17
0
void Logger::init(const char * serverIp)
{
    ASSERT(is_valid_ip(serverIp));
    u32 ip = str_to_ip(serverIp);
    init(ip);
}
Ejemplo n.º 18
0
int
main(int argc, char **argv)
{

	struct layer *proto;
	struct MAC localmac,gwmac,cli_mac;
	uint32_t real_ip,spoof_ip,gw_ip,client_ip,server_ip,dly,
		dly_serv;
	struct TCPSocket ts;
	struct datalink icmp_dl,dl;
	uint16_t start_port,end_port,server_port,
		ip_id_a,ip_id_b,ip_id_d;
	unsigned long i;
	unsigned short guess_port,min_delta=-1;
	unsigned long guess_serv_seq,serv_seq=0;
	uint32_t start_guess,end_guess;
	int guess_inc;
	char icmp_filter[256];
	if( argc < 9 )
		usage(*argv);
	if( argc >=  10){
		errno = 0;
		serv_seq = strtoul(argv[9],NULL,10);
		if(errno)
			serv_seq =0;
	}

	srand(time(NULL));
	memset(&dl,0,sizeof(dl));
	if( if_openbyname(&dl,argv[1]) < 0 ){
		fprintf(stderr,"open_link_byname failed\n");
		return 1;
	}

	memset(&icmp_dl,0,sizeof(dl));
	if( if_openbyname(&icmp_dl,argv[1]) < 0 ){
		fprintf(stderr,"open_link_byname failed\n");
		return 1;
	}
	guess_port = start_port;
	str_to_ip(argv[2],&real_ip);	
	str_to_ip(argv[3],&gw_ip);	
	str_to_ip(argv[4],&spoof_ip);	
	str_to_ip(argv[5],&server_ip);	
	memcpy(&localmac.mac,dl.dl_mac,6);

	snprintf(icmp_filter,sizeof(icmp_filter),"icmp and icmp[0] = 0 and "
		"((src %s and dst %s) or (src %s and dst %s))",
		argv[4],argv[2],argv[5],argv[2]);
	filterDatalink(&icmp_dl,icmp_filter);
	if( dl.dl_pcap->linktype == DLT_EN10MB ){
		if( ARPRequest(&dl,&localmac,&gwmac,real_ip,server_ip,5) < 0 ){
			fprintf(stderr,"lan gateway did not reply arp\n");
		exit(1);
		}



		if( ARPRequest(&dl,&localmac,&cli_mac,real_ip,spoof_ip,5) < 0 ){
			fprintf(stderr,"lan gateway did not reply arp\n");
		exit(1);
		}

	}
	start_port = atoi(argv[6]);
	end_port = atoi(argv[7]);
	server_port = atoi(argv[8]);
	createSocket(&ts,&localmac,&gwmac,spoof_ip,
		server_ip,start_port,server_port);
	ts.rcvwin = 0;
	
	ip_id_a = ip_id_b = ip_id_d = 0;
	echo_get_id(&icmp_dl,&localmac,&gwmac,real_ip,server_ip,
		&dly,&ip_id_a);
	printf("delay to server= %lu\n",dly_serv);		

	echo_get_id(&icmp_dl,&localmac,&cli_mac,real_ip,spoof_ip,
		&dly,&ip_id_a);
	printf("delay = %lu\n",dly);		
	for( i = start_port; i<= end_port; i++ ){

		SYN(&ts,&dl);
		
		usleep((dly+dly_serv));
                echo_get_id(&icmp_dl,&localmac,&cli_mac,real_ip,spoof_ip,
                &dly,&ip_id_b);

		ip_id_d = ip_id_b - ip_id_a;
		ip_id_a = ip_id_b;
		if(ip_id_d < min_delta){
			min_delta = ip_id_d;
			guess_port = i;
		}

		printf("for port %d ip_id delta = %x\n",ts.port,ip_id_d);			if(ip_id_d == 0 ){
			printf( " the client port is: %d\n",ts.port);	exit(0);
		}

		ts.port++;
		ts.seq++;
	}
	printf("guessed port is %d\n",guess_port);
	ts.ip = server_ip;
	ts.port = server_port;
	ts.hostip = spoof_ip;
	ts.hostport = guess_port;

	printf("finding serv.seq using 16k window\n");
	min_delta = -1;
if(serv_seq != 0 ){
	ts.seq = serv_seq+65536;
	ts.gatewaymac = cli_mac;

	echo_get_id(&icmp_dl,&localmac,&gwmac,real_ip,spoof_ip,
		
		&dly,&ip_id_a);


	ts.ack = 0;
	ACK(&ts,&dl);
 	//ts.ack = 2<<30;
	//ACK(&ts,&dl);
		
        echo_get_id(&icmp_dl,&localmac,&gwmac,real_ip,spoof_ip,
                &dly,&ip_id_b);

	ip_id_d = ip_id_b - ip_id_a;

	printf("for seq %lu delta = %d\n",serv_seq,ip_id_d);



	ts.seq = serv_seq;

	echo_get_id(&icmp_dl,&localmac,&gwmac,real_ip,spoof_ip,
		
		&dly,&ip_id_a);


	ts.ack = 0;
	ACK(&ts,&dl);
 	//ts.ack = 2<<30;
	//ACK(&ts,&dl);
		
        echo_get_id(&icmp_dl,&localmac,&gwmac,real_ip,spoof_ip,
                &dly,&ip_id_b);

	ip_id_d = ip_id_b - ip_id_a;

	printf("for seq %lu delta = %d\n",serv_seq+65536,ip_id_d);
	closeDatalink(&dl);
	closeDatalink(&icmp_dl);
	exit(0);
}
	ip_id_a = ip_id_b = ip_id_d = 0;

	ts.gatewaymac = cli_mac;
	echo_get_id(&icmp_dl,&localmac,&gwmac,real_ip,spoof_ip,
		
		&dly,&ip_id_a);
	start_guess = 0xffffffff;
	end_guess = 16385;
	guess_inc = -16384;
	for( i = start_guess; abs(end_guess-i)>=0 ; i +=guess_inc ){


		ts.ack = 0;
		ts.seq = i;
		ACK(&ts,&dl);
	 	//ts.ack = 2<<30;
		//ts.seq=i;
		ACK(&ts,&dl);
		
                echo_get_id(&icmp_dl,&localmac,&gwmac,real_ip,spoof_ip,
                &dly,&ip_id_b);

		ip_id_d = ip_id_b - ip_id_a;
		ip_id_a = ip_id_b;
		if(ip_id_d < min_delta){
			min_delta = ip_id_d;
			guess_serv_seq = i;
			if(min_delta == 1)
			{

			printf("for seq %lu ip_id delta = %x\n",ts.seq,ip_id_d);		

			RST(&ts,&dl);	
			exit(0);
			}

		}

		printf("for seq %lu ip_id delta = %x\n",ts.seq,ip_id_d);		

	}

	printf("guessed sequence = %lu\n",guess_serv_seq);

	ts.seq = guess_serv_seq;
	
	RST(&ts,&dl);	
	closeDatalink(&dl);
	closeDatalink(&icmp_dl);
	return 0;
}
Ejemplo n.º 19
0
int main(int argc, char** argv) {
    int retries = 1;
    int timeout = 5;

    if (argc == 1) {
        fprintf(stdout, "Usage: \n\nresponse_collector \"$DNS_SERVER_NAME\" $SERVER_IP_ADDRESS [timeout=5] [retries=1]\n\nor\n\n");
        fprintf(stdout, "response_collector \"$VENDOR | $PRODUCT | $VERSION\" $SERVER_IP_ADDRESS [timeout=5] [retries=1]\n\nor\n\n");
        fprintf(stdout, "response_collector --show-queries\n\n\n");

        exit(1);
    }

    bool showQueries = (strcmp(argv[1], "--show-queries") == false);
    if (argc == 2 && !showQueries) {
        fprintf(stderr, "Error: Invalid command line argument\n");

        exit(1);
    }

    unsigned int ip_address;
    if (argc > 2) {
        ip_address = str_to_ip(argv[2]);
        
        //0.0.0.0 address will always fail
        if (ip_address == 0) {
            exit(1);
        }
        if (argc >= 4) {
            timeout = atoi(argv[3]);
            if (argc >= 5) {
                retries = atoi(argv[4]);
            }
        }
    }


    DnsResolver oRes;
    oRes.setRetries(retries);
    oRes.setTimeout(timeout);

    if (!showQueries) {
        oRes.setNameserver(ip_address);
    }
    std::string sA = ".";
    DnsName oName(sA);

    DnsRR *pQuestionRR = DnsRR::question(oName, DNS_RR_A);
    pQuestionRR->set_class(DNS_CLASS_IN);

    DnsPacket oQuest(true, -1);
    oQuest.addQuestion(*pQuestionRR);

    int count = 0;
    unsigned opcode;
    unsigned aa;
    unsigned tc;
    unsigned rd;
    unsigned ra;
    unsigned z;
    unsigned ad;
    unsigned cd;
    unsigned rcode_index;
    rcode_t rcodes[NUM_RCODE] = {DNS_NOERROR, DNS_NOTIMP};


    if (showQueries) {
        fprintf(stdout, "ver %s\n", RESPONSE_COLLECTOR_VERSION);
    } else {
        fprintf(stdout, "%s\n", argv[1]);
    }

    for (opcode = 0; opcode < NUM_OPCODE; opcode++) {
        for (aa = 0; aa < NUM_AA; aa++) {
            for (tc = 0; tc < NUM_TC; tc++) {
                for (rd = 0; rd < NUM_RD; rd++) {
                    for (ra = 0; ra < NUM_RA; ra++) {
                        for (z = 0; z < NUM_Z; z++) {
                            for (ad = 0; ad < NUM_AD; ad++) {
                                for (cd = 0; cd < NUM_CD; cd++) {
                                    for (rcode_index = 0; rcode_index < NUM_RCODE; rcode_index++) {
                                        DnsPacket oResp(true);

                                        oQuest.getHeader().setOpcode(opcode);
                                        oQuest.getHeader().set_aa(aa);
                                        oQuest.getHeader().set_tc(tc);
                                        oQuest.getHeader().set_rd(rd);
                                        oQuest.getHeader().set_ra(ra);
                                        oQuest.getHeader().set_z(z);
                                        oQuest.getHeader().set_ad(ad);
                                        oQuest.getHeader().set_cd(cd);
                                        oQuest.getHeader().set_rcode(rcodes[rcode_index]);

                                        if (showQueries) {
                                            printHeader(oQuest.getHeader());
                                            printNameClassType(oQuest);
                                            continue;
                                        }

                                        oRes.send(oQuest, oResp);
                                        if (!oResp.getHeader().getResponse()) {
                                            printHeader(oQuest.getHeader());
                                        } else {
                                            printHeader(oResp.getHeader());
                                        }
                                        count++;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }


    std::string qnames[NUM_QNAME] = {".", "jjjjjjjjjjjj"};
    unsigned qclasses[NUM_QCLASS] = {DNS_CLASS_RESERVED, DNS_CLASS_IN,
        DNS_CLASS_UNASSIGNED, DNS_CLASS_CH, DNS_CLASS_HS, DNS_CLASS_NONE,
        DNS_CLASS_ANY, DNS_CLASS_RESERVED_PRIVATE, DNS_CLASS_RESERVED1};
    unsigned qtypes[NUM_QTYPE] = {DNS_RR_A, DNS_RR_NS, DNS_RR_MD, DNS_RR_CNAME,
        DNS_RR_SOA, DNS_RR_HINFO, DNS_RR_AAAA, DNS_RR_NXT, DNS_RR_A6, DNS_RR_DNAME,
        DNS_RR_SINK, DNS_RR_SSHFP, DNS_RR_RRSIG, DNS_RR_NSEC, DNS_RR_DNSKEY,
        DNS_RR_NSEC3, DNS_RR_NSEC3PARAM, DNS_RR_TKEY, DNS_RR_TSIG, DNS_RR_IXFR,
        DNS_RR_AXFR, DNS_RR_UNASSIGNED, DNS_RR_PRIVATE, DNS_RR_RESERVED};


    for (int i = 0; i < NUM_QNAME; i++) {
        for (int j = 0; j < NUM_QCLASS; j++) {
            for (int k = 0; k < NUM_QTYPE; k++) {

                DnsPacket oResp(true);
                DnsPacket oQuest(true, -1);

                DnsResolver oRes;
                oRes.setRetries(retries);
                oRes.setTimeout(timeout);
                if (!showQueries) {
                    oRes.setNameserver(str_to_ip(argv[2]));
                }
                std::string sA = qnames[i];
                DnsName oName(sA);

                DnsRR *pQuestionRR = DnsRR::question(oName, qtypes[k]);
                pQuestionRR->set_class(qclasses[j]);
                oQuest.addQuestion(*pQuestionRR);

                if (showQueries) {
                    printHeader(oQuest.getHeader());
                    printNameClassType(oQuest);
                    continue;
                }


                oRes.send(oQuest, oResp);
                if (!oResp.getHeader().getResponse()) {
                    printHeader(oQuest.getHeader());
                } else {
                    printHeader(oResp.getHeader());
                }
                count++;
            }
        }
    }


    return 0;
}
Ejemplo n.º 20
0
int main(int argc, char *argv[])
{
    int opt;
    char options[] = "AabcDdEefGgHhijklm?F:n:N:o:P:p:q:r:s:S:t:u:U:v:x:y:V:z:Z:";
    int fd;
    struct acl_args args;
    struct acl_list_args *args2;
    int method=-1;
    int result;
    int i;

    memset(&args, 0, sizeof(struct acl_args));
    args.pn = 7; /* Default do not care*/
    /* Max 511 acl entries */
    args2=malloc(sizeof(struct acl_list_args) + sizeof(struct acl_args)*511);
    if (NULL == args2)
    {
	    printf(" Allocate memory for acl_list_args and acl_args failed.\n");
	    return 0;
    }
    fd = open("/dev/"ACL_DEVNAME, O_RDONLY);

    if (fd < 0)
    {
	printf("Open %s pseudo device failed\n","/dev/"ACL_DEVNAME);
        free(args2);
	return 0;
    }

    if(argc < 2) {
	show_usage();
        free(args2);
        close(fd);
	return 0;
    }

    while ((opt = getopt (argc, argv, options)) != -1) {
	switch (opt) {
	case 'A': 
		method=ACL_ADD_SDMAC_ANY;
		break;
	case 'a': 
		method=ACL_ADD_SMAC_DIP_ANY;
		break;
	case 'b':
		method=ACL_ADD_SMAC_DIP_TCP;
		break;
	case 'c':
		method=ACL_ADD_SMAC_DIP_UDP;
		break;
	case 'D': 
		method=ACL_DEL_SDMAC_ANY;
		break;
	case 'd': 
		method=ACL_DEL_SMAC_DIP_ANY;
		break;
	case 'e':
		method=ACL_DEL_SMAC_DIP_TCP;
		break;
	case 'E':
		method=ACL_ADD_SMAC_DMAC_ETYPE_VID_SIP_DIP_TOS_PORT;
		break;
	case 'F':
                if(strcasecmp(optarg,"TCP")==0){
                            args.L4=ACL_PROTO_TCP;
	                }else if(strcasecmp(optarg,"UDP")==0){
	                        args.L4=ACL_PROTO_UDP;
	                    }else if(strcasecmp(optarg,"ANY")==0){
	                        args.L4=ACL_PROTO_ANY;
	                }else{
                            printf("Error: -t TCP or UDP or ANY\n");
			    free(args2);
			    close(fd);
			    return 0;
                }

		break;
	case 'G':
		method=ACL_DEL_SMAC_DMAC_ETYPE_VID_SIP_DIP_TOS_PORT;
		break;
	case 'f':
		method=ACL_DEL_SMAC_DIP_UDP;
		break;
	case 'H':
		method=ACL_ADD_SIP_DIP_ANY;
		break;
        case 'g':
                method = ACL_GET_ALL_ENTRIES;
		break;
	case 'h':
		method=ACL_ADD_SIP_DIP_TCP;
		break;
	case 'i':
		method=ACL_ADD_SIP_DIP_UDP;
		break;
	case 'j':
		method=ACL_DEL_SIP_DIP_ANY;
		break;
	case 'k':
		method=ACL_DEL_SIP_DIP_TCP;
		break;
	case 'l':
		method=ACL_DEL_SIP_DIP_UDP;
		break;
	case 'm':
		method=ACL_CLEAN_TBL;
		break;
	case 'n': /* source mac address */
		str_to_mac(args.mac, optarg);
		break;
	case 'N': /* destination mac address */
		str_to_mac(args.dmac, optarg);
		break;
	case 'o': /* start of sip */
		str_to_ip(&args.sip_s, optarg);
		break;
	case 'p': /* end of sip */
		str_to_ip(&args.sip_e, optarg);
		break;
	case 'P': /* Port Number */
		args.pn=strtoll(optarg, NULL, 10);
		break;
	case 'q': /* start of dip */
		str_to_ip(&args.dip_s, optarg);
		break;
	case 'r': /* end of dip */
		str_to_ip(&args.dip_e, optarg);
		break;
	case 's': /* start of dp */
		args.dp_s=strtoll(optarg, NULL, 10);
		break;
	case 't': /* end of dp */
		args.dp_e=strtoll(optarg, NULL, 10);
		break;
	case 'S': /* Protocol */
		args.protocol=strtoll(optarg, NULL, 10);
		break;

	case 'v': /* start of sp */
		args.sp_s=strtoll(optarg, NULL, 10);
		break;
	case 'x': /* end of sp */
		args.sp_e=strtoll(optarg, NULL, 10);
		break;
	case 'y': /* start of tos */
		args.tos_s=strtoll(optarg, NULL, 10);
		break;
	case 'z': /* end of tos */
		args.tos_e=strtoll(optarg, NULL, 10);
		break;
	case 'Z': /* ethertype */
		args.ethertype=strtoll(optarg, NULL, 16);
		break;
	case 'V': /* VID */
		args.vid=strtoll(optarg, NULL, 10);
		break;
	case 'u': /* Deny/Allow */
		if(strcasecmp(optarg,"Deny")==0){
			args.method=ACL_DENY_RULE;
		}else if(strcasecmp(optarg,"Allow")==0){
			args.method=ACL_ALLOW_RULE;
		}else if(strcasecmp(optarg,"FP")==0){
			args.method=ACL_PRIORITY_RULE;
		}else{
			printf("Error: -t Deny or Allow\n");
			free(args2);
			close(fd);
			return 0;
		}
		break;
	case 'U': /* User Priority */
		args.up=strtoll(optarg, NULL, 10);
		break;
	case '?':
	default:
	    show_usage();
	    free(args2);
	    close(fd);
            return 0;
	}
    } 
    switch(method) {
    case ACL_ADD_SDMAC_ANY:
    case ACL_ADD_ETYPE_ANY:	
    case ACL_ADD_SMAC_DIP_ANY:
    case ACL_ADD_SMAC_DIP_TCP:
    case ACL_ADD_SMAC_DIP_UDP:
    case ACL_DEL_SDMAC_ANY:
    case ACL_DEL_ETYPE_ANY:
    case ACL_DEL_SMAC_DIP_ANY:
    case ACL_DEL_SMAC_DIP_TCP:
    case ACL_DEL_SMAC_DIP_UDP:
    case ACL_ADD_SIP_DIP_ANY:
    case ACL_ADD_SIP_DIP_TCP:
    case ACL_ADD_SIP_DIP_UDP:
    case ACL_ADD_SMAC_DMAC_ETYPE_VID_SIP_DIP_TOS_PORT:	
    case ACL_DEL_SIP_DIP_ANY:
    case ACL_DEL_SIP_DIP_TCP:
    case ACL_DEL_SIP_DIP_UDP:
    case ACL_DEL_SMAC_DMAC_ETYPE_VID_SIP_DIP_TOS_PORT:
    case ACL_CLEAN_TBL:
	      SetAclEntry(&args, method);
	      result = args.result;
	      break;
    case ACL_GET_ALL_ENTRIES:
	      AclGetAllEntries(args2);
	      result = args2->result;

	      printf("Total Entry Count = %d\n",args2->num_of_entries);
	      for(i=0;i<args2->num_of_entries;i++){
		  printf("#%d :SMAC=%02X:%02X:%02X:%02X:%02X:%02X => DMAC=%02X:%02X:%02X:%02X:%02X:%02X PROTOCOL=0x%2x\n", \
			  i, args2->entries[i].mac[0], args2->entries[i].mac[1], args2->entries[i].mac[2], \
			  args2->entries[i].mac[3], args2->entries[i].mac[4], args2->entries[i].mac[5], \
			  args2->entries[i].dmac[0], args2->entries[i].dmac[1],args2->entries[i].dmac[2], \
			  args2->entries[i].dmac[3], args2->entries[i].dmac[4],args2->entries[i].dmac[5], \
			  args2->entries[i].protocol);

		  printf("   :SIP %u.%u.%u.%u->%u.%u.%u.%u=>DIP %u.%u.%u.%u->%u.%u.%u.%u  SP %d->%d=>DP %d->%d TOS:0x%2x->0x%2x VID:%d ETYPE=0x%4x TCP_UDP=0/TCP=1/UDP=2:%d PN:%d\n\r", \
			  NIPQUAD(args2->entries[i].sip_s), \
			  NIPQUAD(args2->entries[i].sip_e), \
			  NIPQUAD(args2->entries[i].dip_s), \
			  NIPQUAD(args2->entries[i].dip_e), \
			  args2->entries[i].sp_s, \
			  args2->entries[i].sp_e, \
			  args2->entries[i].dp_s, \
			  args2->entries[i].dp_e, \
			  args2->entries[i].tos_s, \
		    args2->entries[i].tos_e, \
		    args2->entries[i].vid, \
		    args2->entries[i].ethertype, \
		    args2->entries[i].L4, \
		    args2->entries[i].pn);
	      }
	      break;
    default:
	      result = ACL_FAIL;
    }


    if(result == ACL_SUCCESS) {
	printf("done\n");
    }else if (result ==  ACL_TBL_FULL) {
	printf("table full\n");
    } else {
	printf("fail\n");
    }
    
    free(args2);
    close(fd);
    return 0;
}
Ejemplo n.º 21
0
int main(int argc, char *argv[])
{
    int opt;
    char options[] = "ABCDabcdefghPQRSpqrstuvwz?m:i:j:k:";
    int fd;
    int method=-1;
    struct ac_args args;
    int result;


    fd = open("/dev/"AC_DEVNAME, O_RDONLY);
    if (fd < 0)
    {
        printf("Open %s pseudo device failed\n","/dev/"AC_DEVNAME);
        return 0;
    }

    if(argc < 2)
    {
        show_usage();
        close(fd);
        return 0;
    }

    while ((opt = getopt (argc, argv, options)) != -1)
    {
        switch (opt)
        {
            case 'a':
                method=AC_ADD_MAC_UL_ENTRY;
                break;
            case 'b':
                method=AC_ADD_MAC_DL_ENTRY;
                break;
            case 'c':
                method=AC_DEL_MAC_UL_ENTRY;
                break;
            case 'd':
                method=AC_DEL_MAC_DL_ENTRY;
                break;
            case 'e':
                method=AC_ADD_IP_UL_ENTRY;
                break;
            case 'f':
                method=AC_ADD_IP_DL_ENTRY;
                break;
            case 'g':
                method=AC_DEL_IP_UL_ENTRY;
                break;
            case 'h':
                method=AC_DEL_IP_DL_ENTRY;
                break;
            case 'A':
                method=AC_ADD_VLAN_UL_ENTRY;
                break;
            case 'B':
                method=AC_ADD_VLAN_DL_ENTRY;
                break;
            case 'C':
                method=AC_DEL_VLAN_UL_ENTRY;
                break;
            case 'D':
                method=AC_DEL_VLAN_DL_ENTRY;
                break;
            case 'p':
                method=AC_GET_MAC_UL_PKT_CNT;
                break;
            case 'q':
                method=AC_GET_MAC_DL_PKT_CNT;
                break;
            case 'r':
                method=AC_GET_MAC_UL_BYTE_CNT;
                break;
            case 's':
                method=AC_GET_MAC_DL_BYTE_CNT;
                break;
            case 't':
                method=AC_GET_IP_UL_PKT_CNT;
                break;
            case 'u':
                method=AC_GET_IP_DL_PKT_CNT;
                break;
            case 'v':
                method=AC_GET_IP_UL_BYTE_CNT;
                break;
            case 'w':
                method=AC_GET_IP_DL_BYTE_CNT;
                break;
            case 'P':
                method=AC_GET_VLAN_UL_PKT_CNT;
                break;
            case 'Q':
                method=AC_GET_VLAN_DL_PKT_CNT;
                break;
            case 'R':
                method=AC_GET_VLAN_UL_BYTE_CNT;
                break;
            case 'S':
                method=AC_GET_VLAN_DL_BYTE_CNT;
                break;
            case 'z': /* CleanTbl */
                method=AC_CLEAN_TBL;
                break;
            case 'm': /* Mac */
                str_to_mac(args.mac, optarg);
                break;
            case 'i': /* IP */
                str_to_ip(&args.ip_s, optarg);
                break;
            case 'j':
                str_to_ip(&args.ip_e, optarg);
                break;
            case 'k':
                args.vid = strtoll(optarg, NULL, 10);
                break;

            case '?': /* Help */
                show_usage();
                break;
        }
    }


    switch(method)
    {
        case AC_ADD_VLAN_UL_ENTRY:
        case AC_ADD_VLAN_DL_ENTRY:
        case AC_ADD_MAC_UL_ENTRY:
        case AC_ADD_MAC_DL_ENTRY:
        case AC_ADD_IP_UL_ENTRY:
        case AC_ADD_IP_DL_ENTRY:
        case AC_CLEAN_TBL:
            SetAcEntry(&args, method);
            result = args.result;
            break;
        case AC_DEL_VLAN_UL_ENTRY:
        case AC_DEL_VLAN_DL_ENTRY:
        case AC_DEL_MAC_UL_ENTRY:
        case AC_DEL_MAC_DL_ENTRY:
        case AC_DEL_IP_UL_ENTRY:
        case AC_DEL_IP_DL_ENTRY:
            SetAcEntry(&args, method);
            result = args.result;
            break;
        case AC_GET_VLAN_UL_PKT_CNT:
        case AC_GET_VLAN_DL_PKT_CNT:
        case AC_GET_MAC_UL_PKT_CNT:
        case AC_GET_MAC_DL_PKT_CNT:
        case AC_GET_IP_UL_PKT_CNT:
        case AC_GET_IP_DL_PKT_CNT:
        case AC_GET_VLAN_UL_BYTE_CNT:
        case AC_GET_VLAN_DL_BYTE_CNT:
        case AC_GET_MAC_UL_BYTE_CNT:
        case AC_GET_MAC_DL_BYTE_CNT:
        case AC_GET_IP_UL_BYTE_CNT:
        case AC_GET_IP_DL_BYTE_CNT:
            result = GetAcEntry(&args, method);
	    printf("Count=%lld\n",args.cnt);
            break;
    default:
         result = AC_FAIL;
    }

    if(result == AC_SUCCESS)
    {
        printf("done\n");
    }
    else if (result ==  AC_TBL_FULL)
    {
        printf("table full\n");
    }
    else
    {
        printf("fail\n");
    }

    close(fd);
    return 0;
}
Ejemplo n.º 22
0
int setup_firewall(firewall_t* fwall, char* in, char* out, char* errbuf) {
	FILE *settings;
	settings = fopen("settings.config", "r");

	if (settings == NULL) {
		return 0;
	}
	
	int read = 0;
	char buff[1024];
	while (fgets(buff, 1024, settings) != NULL) {
		int str_tam = strlen(buff);
  	if (read == 0) {
  		str_to_mac(buff, fwall->virtual_mac); 	
  	} else if (read == 1) {
  		str_to_mac(buff, fwall->firewall_mac);
  	} else if (read == 2) {
  		str_to_mac(buff, fwall->switch_mac);
  	} else if (read == 3) {
  		str_to_mac(buff, fwall->router_mac);
  	} else if (read == 4) {
  		fwall->virtual_ip_str = (char*) malloc(str_tam+1);
  		memcpy(fwall->virtual_ip_str, buff, str_tam);
  		fwall->virtual_ip_str[str_tam] = 0;
  		str_to_ip(fwall->virtual_ip_str, fwall->virtual_ip_bin);		
  	} else if (read == 5) {
  		fwall->firewall_ip_str = (char*) malloc(str_tam+1);
  		memcpy(fwall->firewall_ip_str, buff, str_tam);
  		fwall->firewall_ip_str[str_tam] = 0;
  		str_to_ip(fwall->firewall_ip_str, fwall->firewall_ip_bin);
  	} else if (read == 6) {
  		fwall->switch_ip_str = (char*) malloc(str_tam+1);
  		memcpy(fwall->switch_ip_str, buff, str_tam);
  		fwall->switch_ip_str[str_tam] = 0;
  		str_to_ip(fwall->switch_ip_str, fwall->switch_ip_bin);
  	}
  	read++;
		if (read == MAX_INPUT_LINES)
			break;
	}
	
	if (read != MAX_INPUT_LINES) {
		fclose(settings);
		return 0;
	}
	
	int sz = strlen(in);
	fwall->dev_name_in = (char*) malloc(sz);
	memcpy(fwall->dev_name_in, in, sz);
	sz = strlen(out);
	fwall->dev_name_out = (char*) malloc(sz);
	memcpy(fwall->dev_name_out, out, sz);
	
	fwall->pcap_in_timeout = IN_TIMEOUT;
	fwall->pcap_out_timeout = OUT_TIMEOUT;
	
	NEXT_TCP_PORT = HIGH_PORT;
  NEXT_UDP_PORT = HIGH_PORT;
	
	ONLINE = 1;
	int i;
	for (i=0;i<strlen(fwall->dev_name_in);i++)
		if (fwall->dev_name_in[i] == '.') ONLINE = 0;
	
	if (ONLINE) {	
		if (device_not_found(in, errbuf)) {
			printf("Device %s not found!\n",in);
			return 0;
		}	
		if (device_not_found(out, errbuf)) {
			printf("Device %s not found!\n",out);
			return 0;
		}	
		
		fwall->pcap_in = pcap_open_live(fwall->dev_name_in, BUFSIZ, 0, fwall->pcap_in_timeout, errbuf);	
		if (fwall->pcap_in == NULL) {
			printf("Error pcap in: %s\n", errbuf);
			return 0;
		}
		if (pcap_datalink(fwall->pcap_in) != 1) {
			printf("Not ethernet data-link pcap in!\n");
			return 0;
		}
	
		fwall->pcap_out = pcap_open_live(fwall->dev_name_out, BUFSIZ, 0, fwall->pcap_out_timeout, errbuf);	
		if (fwall->pcap_out == NULL) {
			printf("Error pcap out: %s\n", errbuf);
			return 0;
		}
		if (pcap_datalink(fwall->pcap_out) != 1) {
			printf("Not ethernet data-link pcap out!\n");
			return 0;
		}
	} else {
		fwall->pcap_in = pcap_open_offline(fwall->dev_name_in, errbuf);	
		if (fwall->pcap_in == NULL) {
			printf("Error pcap in: %s\n", errbuf);
			return 0;
		}
		if (pcap_datalink(fwall->pcap_in) != 1) {
			printf("Not ethernet data-link pcap in!\n");
			return 0;
		}
	
		fwall->pcap_out = pcap_open_offline(fwall->dev_name_out, errbuf);	
		if (fwall->pcap_out == NULL) {
			printf("Error pcap out: %s\n", errbuf);
			return 0;
		}
		if (pcap_datalink(fwall->pcap_out) != 1) {
			printf("Not ethernet data-link pcap out!\n");
			return 0;
		}
	}
	
	fclose(settings);
	return 1;
}
Ejemplo n.º 23
0
static void
parse_named_action(enum ofputil_action_code code, const struct flow *flow,
                   struct ofpbuf *b, char *arg)
{
    struct ofp_action_dl_addr *oada;
    struct ofp_action_vlan_pcp *oavp;
    struct ofp_action_vlan_vid *oavv;
    struct ofp_action_nw_addr *oana;
    struct ofp_action_tp_port *oata;

    switch (code) {
    case OFPUTIL_OFPAT_OUTPUT:
        parse_output(b, arg);
        break;

    case OFPUTIL_OFPAT_SET_VLAN_VID:
        oavv = ofputil_put_OFPAT_SET_VLAN_VID(b);
        oavv->vlan_vid = htons(str_to_u32(arg));
        break;

    case OFPUTIL_OFPAT_SET_VLAN_PCP:
        oavp = ofputil_put_OFPAT_SET_VLAN_PCP(b);
        oavp->vlan_pcp = str_to_u32(arg);
        break;

    case OFPUTIL_OFPAT_STRIP_VLAN:
        ofputil_put_OFPAT_STRIP_VLAN(b);
        break;

    case OFPUTIL_OFPAT_SET_DL_SRC:
    case OFPUTIL_OFPAT_SET_DL_DST:
        oada = ofputil_put_action(code, b);
        str_to_mac(arg, oada->dl_addr);
        break;

    case OFPUTIL_OFPAT_SET_NW_SRC:
    case OFPUTIL_OFPAT_SET_NW_DST:
        oana = ofputil_put_action(code, b);
        str_to_ip(arg, &oana->nw_addr);
        break;

    case OFPUTIL_OFPAT_SET_NW_TOS:
        ofputil_put_OFPAT_SET_NW_TOS(b)->nw_tos = str_to_u32(arg);
        break;

    case OFPUTIL_OFPAT_SET_TP_SRC:
    case OFPUTIL_OFPAT_SET_TP_DST:
        oata = ofputil_put_action(code, b);
        oata->tp_port = htons(str_to_u32(arg));
        break;

    case OFPUTIL_OFPAT_ENQUEUE:
        parse_enqueue(b, arg);
        break;

    case OFPUTIL_NXAST_RESUBMIT:
        parse_resubmit(b, arg);
        break;

    case OFPUTIL_NXAST_SET_TUNNEL:
        parse_set_tunnel(b, arg);
        break;

    case OFPUTIL_NXAST_SET_QUEUE:
        ofputil_put_NXAST_SET_QUEUE(b)->queue_id = htonl(str_to_u32(arg));
        break;

    case OFPUTIL_NXAST_POP_QUEUE:
        ofputil_put_NXAST_POP_QUEUE(b);
        break;

    case OFPUTIL_NXAST_REG_MOVE:
        nxm_parse_reg_move(ofputil_put_NXAST_REG_MOVE(b), arg);
        break;

    case OFPUTIL_NXAST_REG_LOAD:
        nxm_parse_reg_load(ofputil_put_NXAST_REG_LOAD(b), arg);
        break;

    case OFPUTIL_NXAST_NOTE:
        parse_note(b, arg);
        break;

    case OFPUTIL_NXAST_SET_TUNNEL64:
        ofputil_put_NXAST_SET_TUNNEL64(b)->tun_id = htonll(str_to_u64(arg));
        break;

    case OFPUTIL_NXAST_MULTIPATH:
        multipath_parse(ofputil_put_NXAST_MULTIPATH(b), arg);
        break;

    case OFPUTIL_NXAST_AUTOPATH:
        autopath_parse(ofputil_put_NXAST_AUTOPATH(b), arg);
        break;

    case OFPUTIL_NXAST_BUNDLE:
        bundle_parse(b, arg);
        break;

    case OFPUTIL_NXAST_BUNDLE_LOAD:
        bundle_parse_load(b, arg);
        break;

    case OFPUTIL_NXAST_RESUBMIT_TABLE:
    case OFPUTIL_NXAST_OUTPUT_REG:
        NOT_REACHED();

    case OFPUTIL_NXAST_LEARN:
        learn_parse(b, arg, flow);
        break;

    case OFPUTIL_NXAST_EXIT:
        ofputil_put_NXAST_EXIT(b);
        break;
    }
}