Пример #1
0
/*
** Adds the interface '*IfDp' as virtual interface to the mrouted API
** 
*/
void addMIF( struct IfDesc *IfDp )
{
    struct mif6ctl MifCtl;
    struct MifDesc *MifDp;

    memset(&MifCtl, 0, sizeof(MifCtl));

    /* search free MifDesc
     */

    for( MifDp = MifDescVc; MifDp < VCEP( MifDescVc ); MifDp++ ) 
    {
        if( MifDp->IfDp == IfDp )   // Already Added
            return;
    }
    
    for( MifDp = MifDescVc; MifDp < VCEP( MifDescVc ); MifDp++ ) 
    {
        if( ! MifDp->IfDp )
            break;
    }
    
    /* no more space
     */
    if( MifDp >= VCEP( MifDescVc ) )
        atlog( LOG_ERR, errno, "addMIF, out of MIF space\n");

    MifDp->IfDp = IfDp;

    MifCtl.mif6c_mifi      = MifDp - MifDescVc; 
    MifCtl.mif6c_flags     = 0;                 /* no register */
    MifCtl.vifc_threshold  = IfDp->threshold;   /* Packet TTL must be at least 1 to pass them */
    MifCtl.mif6c_pifi      = IfDp->index;     /* physical interface index */
    MifCtl.vifc_rate_limit = IfDp->ratelimit;   /* hopefully no limit */

    atlog( LOG_DEBUG, 0, "Inside addMIF: setsockopt MRT6_ADD_MIF Mif-Ix %d PHY Ix %d Fl 0x%x %s\n", 
            MifCtl.mif6c_mifi, MifCtl.mif6c_pifi, MifCtl.mif6c_flags, MifDp->IfDp->Name );

    if( setsockopt( MRouterFD, IPPROTO_IPV6, MRT6_ADD_MIF, (char *)&MifCtl, sizeof( MifCtl ) ) )
    {
        atlog( LOG_ERR, errno, "\nMRT6_ADD_MIF failed %s\n\n", IfDp->Name );     
    }
    else
    {
        atlog( LOG_DEBUG, 0, "\nMRT6_ADD_MIF OK %s\n\n", IfDp->Name );             
    }
}
Пример #2
0
int addVIF( struct IfDesc *IfDp )
/*
** Adds the interface '*IfDp' as virtual interface to the mrouted API
** 
*/
{
  struct vifctl VifCtl;
  struct VifDesc *VifDp;

	/*check if IfDp has beed added*/
	 for( VifDp = VifDescVc; VifDp < VCEP( VifDescVc ); VifDp++ ) {
	 	//printf("%s: name=%s\n",__FUNCTION__,VifDp->IfDp->Name);
		if( VifDp->IfDp  && strcmp(VifDp->IfDp->Name,IfDp->Name)==0)
			return VifDp - VifDescVc; 
	}
  /* search free VifDesc
   */
  for( VifDp = VifDescVc; VifDp < VCEP( VifDescVc ); VifDp++ ) {
    if( ! VifDp->IfDp )
      break;
  }
    
  /* no more space
   */
  if( VifDp >= VCEP( VifDescVc ) )
    log( LOG_ERR, ENOMEM, "addVIF, out of VIF space" );

  VifDp->IfDp = IfDp;

  VifCtl.vifc_vifi  = VifDp - VifDescVc; 
  VifCtl.vifc_flags = 0;        /* no tunnel, no source routing, register ? */
  VifCtl.vifc_threshold = 1;    /* Packet TTL must be at least 1 to pass them */
  VifCtl.vifc_rate_limit = 0;   /* hopefully no limit */
  VifCtl.vifc_lcl_addr.s_addr = VifDp->IfDp->InAdr.s_addr;
  VifCtl.vifc_rmt_addr.s_addr = INADDR_ANY;

  log( LOG_NOTICE, 0, "adding VIF, idx=%d Fl flags=0x%x IP=%s %s", 
       VifCtl.vifc_vifi, VifCtl.vifc_flags,  inet_ntoa(VifCtl.vifc_lcl_addr), VifDp->IfDp->Name );

  if( setsockopt( MRouterFD, IPPROTO_IP, MRT_ADD_VIF, 
		  (char *)&VifCtl, sizeof( VifCtl ) ) )
    log( LOG_ERR, errno, "MRT_ADD_VIF" );
  
  IfDp->vif_idx = VifCtl.vifc_vifi;
  
  return VifCtl.vifc_vifi;
}
Пример #3
0
/*
** Adds the interface '*IfDp' as virtual interface to the mrouted API
**
*/
void addVIF( struct IfDesc *IfDp )
{
    struct vifctl VifCtl;
    struct VifDesc *VifDp;

    /* search free VifDesc
     */
    for ( VifDp = VifDescVc; VifDp < VCEP( VifDescVc ); VifDp++ ) {
        if ( ! VifDp->IfDp )
            break;
    }

    /* no more space
     */
    if ( VifDp >= VCEP( VifDescVc ) )
        my_log( LOG_ERR, ENOMEM, "addVIF, out of VIF space" );

    VifDp->IfDp = IfDp;

    VifCtl.vifc_vifi  = VifDp - VifDescVc;
    VifCtl.vifc_flags = 0;        /* no tunnel, no source routing, register ? */
    VifCtl.vifc_threshold  = VifDp->IfDp->threshold;    // Packet TTL must be at least 1 to pass them
    VifCtl.vifc_rate_limit = VifDp->IfDp->ratelimit;    // Ratelimit

    VifCtl.vifc_lcl_addr.s_addr = VifDp->IfDp->InAdr.s_addr;
    VifCtl.vifc_rmt_addr.s_addr = INADDR_ANY;

    // Set the index...
    VifDp->IfDp->index = VifCtl.vifc_vifi;

    my_log( LOG_NOTICE, 0, "adding VIF, Ix %d Fl 0x%x IP 0x%08x %s, Threshold: %d, Ratelimit: %d",
            VifCtl.vifc_vifi, VifCtl.vifc_flags,  VifCtl.vifc_lcl_addr.s_addr, VifDp->IfDp->Name,
            VifCtl.vifc_threshold, VifCtl.vifc_rate_limit);

    struct SubnetList *currSubnet;
    for(currSubnet = IfDp->allowednets; currSubnet; currSubnet = currSubnet->next) {
        my_log(LOG_DEBUG, 0, "        Network for [%s] : %s",
               IfDp->Name,
               inetFmts(currSubnet->subnet_addr, currSubnet->subnet_mask, s1));
    }

    if ( setsockopt( MRouterFD, IPPROTO_IP, MRT_ADD_VIF,
                     (char *)&VifCtl, sizeof( VifCtl ) ) )
        my_log( LOG_ERR, errno, "MRT_ADD_VIF" );

}
Пример #4
0
/*
** Returns for the virtual interface index for '*IfDp'
**
** returns: - the vitrual interface index if the interface is registered
**          - -1 if no virtual interface exists for the interface
**
*/
int getVifIx( struct IfDesc *IfDp )
{
    struct VifDesc *Dp;

    for ( Dp = VifDescVc; Dp < VCEP( VifDescVc ); Dp++ )
        if ( Dp->IfDp == IfDp )
            return Dp - VifDescVc;

    return -1;
}
Пример #5
0
int getVifIx( struct IfDesc *IfDp )
/*
** Returns for the virtual interface index for '*IfDp'
**
** returns: - the vitrual interface index if the interface is registered
**          - -1 if no virtual interface exists for the interface 
**          
*/
{
  struct VifDesc *Dp;

  for( Dp = VifDescVc; Dp < VCEP( VifDescVc ); Dp++ ) 
    if( Dp->IfDp == IfDp )
      return Dp - VifDescVc;

  return -1;
}