Example #1
0
int_32 Shell_arpdel(int_32 argc, char_ptr argv[] )
{ /* Body */
   boolean           print_usage, shorthelp = FALSE;
   int_32            return_code = SHELL_EXIT_SUCCESS;
   _ip_address       ipaddr;
   _rtcs_if_handle   ihandle = ipcfg_get_ihandle (BSP_DEFAULT_ENET_DEVICE);
  
   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
      if (argc != 2)  {
         return_code = SHELL_EXIT_ERROR;
         print_usage = TRUE;
      } else  if (! Shell_parse_ip_address( argv[1], &ipaddr))  {
          printf("Error, invalid ip address\n");
          return_code = SHELL_EXIT_ERROR;
      }
      if (return_code == SHELL_EXIT_SUCCESS) {
          RTCS_arp_delete(ihandle,ipaddr);
      }
   }
   
   if (print_usage)  {
      if (shorthelp)  {
         printf("%s <ip_address>\n", argv[0]);
      } else  {
         printf("Usage: %s <ip_address> \n", argv[0]);
         printf("   <ip_address>  = IP Address\n");
      }
   }

   return return_code;
} /* Endbody */
Example #2
0
int_32 Shell_getroute(int_32 argc, char_ptr argv[] )
{ /* Body */
   boolean           print_usage, shorthelp = FALSE;
   int_32            return_code = SHELL_EXIT_SUCCESS;

   _ip_address       gate_ipaddr;
   _ip_address       ipaddr;
   _ip_address       ipmask;
  
   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
      if (argc != 2)  {
         return_code = SHELL_EXIT_ERROR;
         print_usage = TRUE;
      } else  {
         if (! Shell_parse_ip_address( argv[1], &ipaddr  ))  {
            printf("Error, invalid ip address\n");
            return_code = SHELL_EXIT_ERROR;
         } else if (argc > 2)  {
            if (! Shell_parse_ip_address( argv[2], &ipmask  ))  {
               printf("Error, invalid ip mask\n");
               return_code = SHELL_EXIT_ERROR;
            }
         }          
      }          
         
         
      if (return_code == SHELL_EXIT_SUCCESS)  {
         gate_ipaddr = RTCS_get_route(ipaddr, ipmask);
         printf("The route to ip address: %d.%d.%d.%d, netmask: %d.%d.%d.%d is gateway %d.%d.%d.%d\n",
            IPBYTES(ipaddr),IPBYTES(ipmask),IPBYTES(gate_ipaddr));
      } 
   }

   if (print_usage)  {
      if (shorthelp)  {
         printf("%s <ipaddr> <netmask>\n", argv[0]);
      } else  {
         printf("Usage: %s <ipaddr> <netmask>\n", argv[0]);
         printf("   <ipaddr>  = IP address \n");
         printf("   <netmask> = Network mask\n");
      }
   }

   return return_code;
} /* Endbody */
Example #3
0
int_32  Shell_natinit(int_32 argc, char_ptr argv[] )
{
   uint_32              error;
   boolean              print_usage, shorthelp = FALSE;
   int_32               return_code = SHELL_EXIT_SUCCESS;
   _ip_address          addr, mask;

   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
      if (argc == 3)  {
         if (! Shell_parse_ip_address( argv[1], &addr  ))  {
            printf("Error, invalid ip address\n");
            return_code = SHELL_EXIT_ERROR;
         } else if (! Shell_parse_netmask( argv[2], &mask  ))  {
            printf("Error, invalid ip address\n");
            return_code = SHELL_EXIT_ERROR;
         } else {
            error = NAT_init( addr, mask );
            if (error != RTCS_OK) {
               printf("Error initializing NAT: %s\n",NAT_err_str(error));
               return_code = SHELL_EXIT_ERROR;
            } else {
               printf("NAT Initialized\n");
            }
         }
      } else {
         print_usage = TRUE;
         return_code = SHELL_EXIT_ERROR;
      }
   }

   if (print_usage)  {
      if (shorthelp)  {
         printf("%s <ipaddress> <netmask>\n", argv[0]);
      } else  {
         printf("Usage: %s <ipaddress> <netmask>\n",argv[0]);
      }
   }
   return return_code;
} /* Endbody */
Example #4
0
boolean Shell_parse_netmask( char_ptr arg, _ip_address _PTR_ ipaddr_ptr)
{
   uint_32  i, mask;
   boolean  ones = FALSE;
   
   if ( ipaddr_ptr == NULL) return FALSE;
   
   if (!Shell_parse_ip_address(arg, ipaddr_ptr))  return FALSE;

   
   for (i=0;i<32;i++)  {
      mask = *ipaddr_ptr & (1<<i); 
      if (!ones)  {
         if (mask)  {
            ones = TRUE;
         }
      } else {
         if  (! mask)  {
            return FALSE;   
         }  
      } 
   }   
   return TRUE;
}
static int32_t Shell_ipconfig_dhcp (uint32_t enet_device, uint32_t index, int32_t argc, char *argv[])
{
    uint32_t                     error;
    IPCFG_IP_ADDRESS_DATA       auto_ip_data;
    bool                     auto_ip = FALSE ;

    if (argc > ++index)
    {
        if (strcmp (argv[index], "noauto") == 0)
        {
            auto_ip = FALSE;
        }
        else
        {
            if (! Shell_parse_ip_address (argv[index], &auto_ip_data.ip))
            {
                printf ("Error in dhcp command, invalid ip address!\n");
                return SHELL_EXIT_ERROR;
            }

            if (argc > ++index)
            {
                if (! Shell_parse_ip_address (argv[index], &auto_ip_data.mask))
                {
                    printf ("Error in dhcp command, invalid mask!\n");
                    return SHELL_EXIT_ERROR;
                }
            }
            else
            {
                printf ("Error in dhcp command, missing mask parameter!\n");
                return SHELL_EXIT_ERROR;
            }

#if RTCSCFG_ENABLE_GATEWAYS
            if (argc > ++index)
            {
                if (! Shell_parse_ip_address (argv[index], &auto_ip_data.gateway))
                {
                    printf ("Error dhcp command, invalid gateway!\n");
                    return SHELL_EXIT_ERROR;
                }
            }
            else
            {
                printf ("Error in dhcp command, missing gateway parameter!\n");
                return SHELL_EXIT_ERROR;
            }
#endif
            auto_ip = TRUE;
        }
    }

    error = ipcfg_bind_dhcp_wait (enet_device, auto_ip, &auto_ip_data);
    if (error != IPCFG_OK)
    {
        printf ("Error during dhcp bind %08x!\n", error);
        return SHELL_EXIT_ERROR;
    }

    printf ("Bind via dhcp successful.\n");
    return SHELL_EXIT_SUCCESS;
}
static int32_t Shell_ipconfig_staticip (uint32_t enet_device, uint32_t index, int32_t argc, char *argv[])
{
    uint32_t                 error;

#if RTCSCFG_ENABLE_IP4
    IPCFG_IP_ADDRESS_DATA   ip_data;
#endif


#if RTCSCFG_ENABLE_IP6
    /*IPv6 adds*/
    struct addrinfo         hints;          // used for getaddrinfo()
    struct addrinfo         * addrinfo_res; // used for getaddrinfo()
    IPCFG6_BIND_ADDR_DATA	ip6_bind_data;  // structure for bind interface
    in6_addr                ip6;
#endif
    /* Here we need validate IP address and detect it family */
    /* Dont forget destroy addrinfo_res by freeaddrinfo(addrinfo_res) */


#if RTCSCFG_ENABLE_IP6

    memset(&hints,0,sizeof(hints));
    hints.ai_family 	= AF_UNSPEC;
    hints.ai_socktype 	= SOCK_DGRAM;
    hints.ai_flags 		= AI_NUMERICHOST;
    if (getaddrinfo ( argv[index+1], NULL, &hints, &addrinfo_res) != 0)
    {
        printf("GETADDRINFO error\n");
        return(SHELL_EXIT_ERROR); // we can return right here and do not need free freeaddrinfo(addrinfo_res)
    }
    if(addrinfo_res->ai_family == AF_INET6)
    {
        IN6_ADDR_COPY(&((struct sockaddr_in6 *)((*addrinfo_res).ai_addr))->sin6_addr,&ip6_bind_data.ip_addr);
        ip6_bind_data.ip_addr_type = IP6_ADDR_TYPE_MANUAL;
        freeaddrinfo(addrinfo_res);



        error = ipcfg6_bind_addr (enet_device, &ip6_bind_data);
        if (error != RTCS_OK)
        {
            printf("\nIPCFG Bind IP6(1) is failed, error = %X\n", error);
            return SHELL_EXIT_ERROR;
        }
        printf ("IP6 bind successful.\n");
        return SHELL_EXIT_SUCCESS;
    }
#if RTCSCFG_ENABLE_IP4

    else if(addrinfo_res->ai_family == AF_INET)
    {
        freeaddrinfo(addrinfo_res);
#endif

#endif //RTCSCFG_ENABLE_IP6

#if RTCSCFG_ENABLE_IP4

        if (argc > ++index)
        {
            if (! Shell_parse_ip_address (argv[index], &ip_data.ip))
            {
                printf ("Error in static ip command, invalid ip address!\n");
                return SHELL_EXIT_ERROR;
            }
        }
        else
        {
            printf ("Error in static ip command, missing ip address parameter!\n");
            return SHELL_EXIT_ERROR;
        }

        if (argc > ++index)
        {
            if (! Shell_parse_ip_address (argv[index], &ip_data.mask))
            {
                printf ("Error in static ip command, invalid mask!\n");
                return SHELL_EXIT_ERROR;
            }
        }
        else
        {
            printf ("Error in static ip command, missing mask parameter!\n");
            return SHELL_EXIT_ERROR;
        }

#if RTCSCFG_ENABLE_GATEWAYS
        if (argc > ++index)
        {
            if (! Shell_parse_ip_address (argv[index], &ip_data.gateway))
            {
                printf ("Error in static ip command, invalid gateway!\n");
                return SHELL_EXIT_ERROR;
            }
        }
#endif

        error = ipcfg_bind_staticip (enet_device, &ip_data);
        if (error != 0)
        {
            printf ("Error during static ip bind %08x!\n", error);
            return SHELL_EXIT_ERROR;
        }

        printf ("Static IP4 bind successful.\n");
        return SHELL_EXIT_SUCCESS;
#endif


#if RTCSCFG_ENABLE_IP6
#if RTCSCFG_ENABLE_IP4
    }//end if family
#endif
    printf ("Static bind unsuccessful. Unknown family detected.\n");
    return SHELL_EXIT_ERROR;
#endif


}
Example #7
0
int_32  Shell_dnat(int_32 argc, char_ptr argv[] )
{
   uint_32              error;
   boolean              print_usage, shorthelp = FALSE;
   int_32               return_code = SHELL_EXIT_SUCCESS;
   uint_32              priority=0;     
   uint_16              protocol=0;
   uint_16              start_port=0;   
   uint_16              end_port=0;     
   _ip_address          target_ip=0;      
   uint_16              target_port=0;  

   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
      if (argc == 7)  {
         if (!Shell_parse_uint_32(argv[1], &priority  )) {
            printf("Error, invalid rule priority\n");
            return_code = SHELL_EXIT_ERROR;
         } else if (!Shell_parse_uint_16(argv[3], &start_port  )) {
            printf("Error, invalid start port\n");
            return_code = SHELL_EXIT_ERROR;
         } else if (!Shell_parse_uint_16(argv[4], &end_port  )) {
            printf("Error, invalid end port\n");
            return_code = SHELL_EXIT_ERROR;
         } else if (! Shell_parse_ip_address( argv[5], &target_ip  ))  {
            printf("Error, invalid ip address\n");
            return_code = SHELL_EXIT_ERROR;
         } else if (!Shell_parse_uint_16(argv[6], &target_port  )) {
            printf("Error, invalid target port\n");
            return_code = SHELL_EXIT_ERROR;
         } else {
            if (strcmp(argv[2],"TCP")==0) {
               protocol = IPPROTO_TCP;
            } else if (strcmp(argv[2],"UDP")==0) {
               protocol = IPPROTO_UDP;
            } else {
               printf("Error, invalid protocol\n");
               return_code = SHELL_EXIT_ERROR;
            }
         }
         if (return_code == SHELL_EXIT_SUCCESS) {
            printf("Adding rule:\n");
            printf("%d: %s (%d-%d) -> %03d.%03d.%03d.%03d:%d",
               priority, protocol==IPPROTO_TCP?"TCP":"UDP",start_port,end_port, 
               IPBYTES(target_ip), target_port);

            error = DNAT_add_rule(priority, protocol, start_port, end_port, target_ip, target_port );
            if (error != RTCS_OK) {
               printf("   Error: %s\n",NAT_err_str(error));
               return_code = SHELL_EXIT_ERROR;
            } else {
               printf("   OK\n");
            }
         }
      } else {
         print_usage = TRUE;
         return_code = SHELL_EXIT_ERROR;
      }
   }

   if (print_usage)  {
      if (shorthelp)  {
         printf("%s <priority> TCP|UDP <start_port> <end_port> <target_ip> <target_port>\n", argv[0]);
      } else  {
         printf("Usage: %s <priority> TCP|UDP <start_port> <end_port> <target_ip> <target_port>\n",argv[0]);
      }
   }
   return return_code;
} /* Endbody */