/* Remove virtual IP interfaces from the system. */
void ssh_vxworks_virtual_adapter_uninit(void)
{
  VxWorksVa *va;
  int i;
  STATUS status;

  for (i = 0; i < vxworks_va_num; i++)
    {
      va = &vxworks_va_tab[i];

      if (!va->cookie)
        continue;

#if defined(WITH_IPV6) && defined(INET6)
      if (ip6Detach(i, vxworks_va_devname) != OK)
        SSH_TRACE(SSH_D_ERROR, ("%s: ip6Detach failed", va->name));
#endif /* defined(WITH_IPV6) && defined(INET6) */

      if (ipDetach(i, vxworks_va_devname) != OK)
        SSH_TRACE(SSH_D_ERROR, ("%s: ipDetach failed", va->name));

      if ((status = muxDevStop(va->cookie)) != OK)
        SSH_TRACE(
          SSH_D_ERROR,
          ("%s: muxDevStop failed, status %d", va->name, (int)status));

      if ((status = muxDevUnload(vxworks_va_devname, i)) != OK)
        SSH_TRACE(
          SSH_D_ERROR,
          ("%s: muxDevUnload failed, status %d", va->name, (int)status));

      va->cookie = NULL;
    }
}
Пример #2
0
Файл: if.c Проект: ariavie/bcm
static int
sal_if_do_deconfig(char *pfx, END_OBJ *eo, char *if_name, int if_unit)
/*
 * Function: 
 * Purpose:
 * Parameters:
 * Returns:
 */
{
#if VX_VERSION == 66 || VX_VERSION == 68
    char ifconfigstr[32];
#endif /* VX_VERSION == 66 || VX_VERSION == 68 */

    LOG_INFO(BSL_LS_APPL_END,
             (BSL_META("%s: Stopping %s %d %08x \n"),
              pfx, if_name, if_unit, (uint32)eo));
    if (OK != muxDevStop(eo)) {
	cli_out("%s: Error: muxDevStop failed: %s%d\n", 
                pfx, if_name, if_unit);
	return(-1);
    }

#if VX_VERSION == 66 || VX_VERSION == 68
    sprintf(ifconfigstr, "%s%d down", if_name, if_unit);
    if (ERROR == ifconfig(ifconfigstr)) {
        cli_out("%s: ifconfig down failed: %s%d <-- %s\n", pfx, if_name, if_unit, ifconfigstr);
        return(-1);
    }

    sprintf(ifconfigstr, "%s%d detach", if_name, if_unit);
    if (ERROR == ifconfig(ifconfigstr)) {
        cli_out("%s: ifconfig down failed: %s%d <-- %s\n", pfx, if_name, if_unit, ifconfigstr);
        return(-1);
    }
#else /* VX_VERSION == 66 || VX_VERSION == 68 */

    LOG_INFO(BSL_LS_APPL_END,
             (BSL_META("%s: Clearing Routes\n"), pfx));

#ifdef VXWORKS_NETWORK_STACK_6_5
#ifdef VXWORKS_NETWORK_STACK_FIXME_SHOW
#error VXWORKS_NETWORK_STACK_FIXME_SHOW
#endif 
#else
    ifRouteDelete(if_name, if_unit);
#endif /* VXWORKS_NETWORK_STACK_6_5 */

    LOG_INFO(BSL_LS_APPL_END,
             (BSL_META("%s: Unloading\n"), pfx));
    if (OK != muxDevUnload(if_name, if_unit)) {
	cli_out("%s: Error: muxDevUnload failed: %s%d\n",
                pfx, if_name, if_unit);
	return(-1);
    }
    LOG_INFO(BSL_LS_APPL_END,
             (BSL_META("%s: Stopped and Unloaded: %s%d\n"), 
              pfx, if_name, if_unit));
#endif /* VX_VERSION == 66 || VX_VERSION == 68 */
    return(0);
}
/* Add virtual IP interfaces to the system. */
void ssh_vxworks_virtual_adapter_init(void)
{
  VxWorksVa *va;
  STATUS status;
  int i, started, ip_attached;
  void *cookie;
  unsigned short if_index;

  vxworks_va_nettask = taskIdSelf();

  for (i = 0; i < vxworks_va_num; i++)
    {
      va = &vxworks_va_tab[i];
      started = 0;
      ip_attached = 0;

      memset(va, 0, sizeof *va);

      ssh_snprintf(va->name, sizeof va->name, "%s%d", vxworks_va_devname, i);

      memset(va->enet_addr, 0, sizeof va->enet_addr);
      memcpy(va->enet_addr, vxworks_va_oui, sizeof vxworks_va_oui);
      va->enet_addr[sizeof va->enet_addr - 1] = (unsigned char)i;

      if (!(cookie = muxDevLoad(i, vxworks_va_load, "", FALSE, va)))
        {
          SSH_TRACE(SSH_D_ERROR, ("%s: muxDevLoad failed", va->name));
          goto fail;
        }

      if ((status = muxDevStart(cookie)) != OK)
        {
          SSH_TRACE(
            SSH_D_ERROR,
            ("%s: muxDevStart failed, status %d", va->name, (int)status));
          goto fail;
        }
      started = 1;

      if (ipAttach(i, vxworks_va_devname) != OK)
        {
          SSH_TRACE(SSH_D_ERROR, ("%s: ipAttach failed", va->name));
          goto fail;
        }
      ip_attached = 1;

#if defined(WITH_IPV6) && defined(INET6)
      if (ip6Attach(i, vxworks_va_devname) != OK)
        {
          SSH_TRACE(SSH_D_ERROR, ("%s: ip6Attach failed", va->name));
          goto fail;
        }
#endif /* defined(WITH_IPV6) && defined(INET6) */

      if (!(if_index = ifNameToIfIndex(va->name)))
        {
          SSH_TRACE(
            SSH_D_ERROR,
            ("%s: cannot get interface index after IP attach", va->name));
          goto fail;
        }

      va->ifnum = if_index - 1;
      va->cookie = cookie;

      continue;

    fail:
      if (ip_attached)
        ipDetach(i, vxworks_va_devname);

      if (started)
        muxDevStop(cookie);

      if (cookie)
        muxDevUnload(vxworks_va_devname, i);
    }
}
Пример #4
0
Файл: if.c Проект: ariavie/bcm
static void *
sal_if_config(char *pfx, int u, char *if_name, int if_unit, 
	      char *if_host, sal_mac_addr_t if_mac, int if_vlan, 
	      sal_ip_addr_t if_ip, sal_ip_addr_t if_netmask)
/*
 * Function: 	sal_if_config
 * Purpose:	Configure a network device (load driver and start)
 * Parameters:	pfx - string printed for error messages.
 *		name - device name ("sn" for "sn0")
 *		unit - unint number (0 for "sn0")
 * Returns:	NULL - failed
 *		!NULL - opaque pointer.
 */
{
#ifdef INCLUDE_DRIVERS
    extern END_OBJ *socend_load(char *is, void *);
    char	if_name_str[END_NAME_MAX];
    char	if_init_str[64];
    char 	if_ip_str[SAL_IPADDR_STR_LEN];
    char	if_mac_str[SAL_MACADDR_STR_LEN];
    END_OBJ	*eo;			/* END object  */
#if VX_VERSION == 64 || VX_VERSION == 65 || VX_VERSION == 66 || VX_VERSION == 68
#else
    M2_INTERFACETBL	m2;
#endif
#if VX_VERSION == 66 || VX_VERSION == 68
    char if_cfg_str[256];
    char if_mask_str[SAL_IPADDR_STR_LEN];
#endif

    SAL_MAP_NETUNIT(if_unit);
    LOG_INFO(BSL_LS_APPL_END,
             (BSL_META_U(u,
                         "%s: sal_if_config *** if_name=%s if_unit=%d\n"), 
              pfx, if_name, if_unit));
    /* Build vxWorks device name */
    sprintf(if_name_str, "%s%d", if_name, if_unit);

    /* Check to see if end device already loaded */

    if (NULL == (eo = endFindByName(if_name, if_unit))) {
	LOG_INFO(BSL_LS_APPL_END,
                 (BSL_META_U(u,
                             "%s: End device not loaded: if %s if_unit %d\n"), 
                  pfx, if_name, if_unit));
	format_macaddr(if_mac_str, if_mac);
	sprintf(if_init_str, "%d:%s:%d", u, if_mac_str, if_vlan);
	if (NULL == (eo = muxDevLoad(if_unit, socend_load, 
				     if_init_str, 0, NULL))) {
	    cli_out("%s: muxDevLoad failed: Unit %d\n", pfx, u);
	    return(NULL);
	}

	LOG_INFO(BSL_LS_APPL_END,
                 (BSL_META_U(u,
                             "%s: muxDevLoad successful: 0x%x\n"), pfx, (int)eo));
	if (ERROR == muxDevStart(eo)) {
	    cli_out("%s: muxDevStart failed: Unit %d\n", pfx, u);
	    (void)muxDevUnload(if_name, if_unit);
	    return(NULL);
	}
	LOG_INFO(BSL_LS_APPL_END,
                 (BSL_META_U(u,
                             "%s: muxDevStart successful: 0x%x\n"), pfx, (int)eo));
    }
#if VX_VERSION == 64 || VX_VERSION == 65 || VX_VERSION == 66 || VX_VERSION == 68
#else
    /*
     * Configure device....
     */
    if (OK != muxIoctl(eo, EIOCGMIB2, (caddr_t)&m2)) {
        cli_out("%s: muxIoctl failed: Unit %d\n", pfx, u);
	(void)sal_if_do_deconfig(pfx, eo, if_name, if_unit);
	return(NULL);
    }
    LOG_INFO(BSL_LS_APPL_END,
             (BSL_META_U(u,
                         "%s: muxIOCTL successful: Unit %d\n"), pfx, u));
#endif /* VX_VERSION */

    /*
     * Setup interface in following order:
     *		[1] Attach TCP/IP to END device
     *		[2] Set Netmask (if non-0)
     *		[3] Set IP address
     *		[4] Set host name associated with interface (if given).
     */
    if (OK != ipAttach(if_unit, if_name)) { /* [1] */
        cli_out("%s: ipAttach failed: Unit %d (interface %s)\n", 
                pfx, u, if_name_str);
	(void)sal_if_do_deconfig(pfx, eo, if_name, if_unit);
	return(NULL);
    }
    LOG_INFO(BSL_LS_APPL_END,
             (BSL_META_U(u,
                         "%s: ipAttach successful: if_name %s if_unit %d\n"), 
              pfx, if_name, if_unit));

#if VX_VERSION == 66 || VX_VERSION == 68

    format_ipaddr(if_ip_str, if_ip);	/* [3] */

    if (0 != if_netmask) {		/* [2] */
        format_ipaddr(if_mask_str, if_netmask);	/* [3] */
    }

    sprintf(if_cfg_str, "%s up inet add %s netmask %s", if_name_str, if_ip_str, if_mask_str);
   
    if (ERROR == ifconfig(if_cfg_str)) {
        cli_out("%s: ifconfig failed: %s%d: %s\n",
                pfx, if_name, if_unit, if_cfg_str);
        (void)sal_if_do_deconfig(pfx, eo, if_name, if_unit);
        return(NULL);
    }
    LOG_INFO(BSL_LS_APPL_END,
             (BSL_META_U(u,
                         "%s: ifconfig: if %s, cfg str %s\n"),
              pfx, if_name_str, if_cfg_str));
#else
    if (0 != if_netmask) {		/* [2] */
#ifdef VXWORKS_NETWORK_STACK_6_5
#ifdef VXWORKS_NETWORK_STACK_FIXME_SHOW
#error VXWORKS_NETWORK_STACK_FIXME     
#endif   
#else 
	if (ERROR == ifMaskSet(if_name_str, if_netmask)) {
	    cli_out("%s: ifMaskSet failed: %s 0x%x\n", 
                    pfx, if_name_str, if_netmask);
	    (void)sal_if_do_deconfig(pfx, eo, if_name, if_unit);
	    return(NULL);
	}
#endif 
    }

    format_ipaddr(if_ip_str, if_ip);	/* [3] */
#ifdef VXWORKS_NETWORK_STACK_6_5
#ifdef VXWORKS_NETWORK_STACK_FIXME_SHOW
#error VXWORKS_NETWORK_STACK_FIXME
#endif
#else
    if (OK != ifAddrSet(if_name_str, (char *)if_ip_str)) {
	cli_out("%s: ifAddrSet failed: %s <-- %s\n", pfx, if_name, if_ip_str);
	(void)sal_if_do_deconfig(pfx, eo, if_name, if_unit);
	return(NULL);
    }
#endif 

    LOG_INFO(BSL_LS_APPL_END,
             (BSL_META_U(u,
                         "%s: ifAddrSet successful: if %s\n"), pfx, if_name_str));
#endif

    if (if_host && *if_host) {		/* [4] */
	LOG_INFO(BSL_LS_APPL_END,
                 (BSL_META_U(u,
                             "%s: Setting hostname: %s\n"), pfx, if_host));
	if (OK != hostAdd (if_host, if_ip_str)) {
	    cli_out("%s: Warning: Failed to set hostname %s for device %s\n", 
                    pfx, if_host, if_name_str);
	}
    }

    return((void *)eo);			/* This is our opaque value */
#else /* !defined(INCLUDE_DRIVERS) */
    cli_out("sal_if_config: Interface configuration not compiled in\n");
    return(NULL);
#endif /* !defined(INCLUDE_DRIVERS) */
}