Guest User

Untitled

a guest
Jun 21st, 2012
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.26 KB | None | 0 0
  1.  
  2. void addTvlvNode(struct batadv_priv *bat_priv,struct shortTvlv *tvlv){
  3.         struct batadv_shortTvlv_node *tvlv_node=0;
  4.         if(!bat_priv || !tvlv)
  5.         goto end;
  6.        
  7.         tvlv_node=kmalloc(sizeof(struct batadv_shortTvlv_node), GFP_KERNEL);
  8.         printk("New node allocated\n");
  9.        
  10.         if (!tvlv_node)
  11.                 return;
  12.                
  13.         INIT_HLIST_NODE(&tvlv_node->tlist);
  14.        printk("New node inited\n");
  15.      
  16.         spin_lock_bh(&bat_priv->tvlv_list_lock);
  17.          tvlv_node->sTvlv=tvlv;
  18.           printk("New node assigned\n");
  19.          
  20.          
  21.         hlist_add_head_rcu(&tvlv_node->tlist, &bat_priv->tvlv_list);
  22.          printk("New node put in list\n");
  23.          
  24.         spin_unlock_bh(&bat_priv->tvlv_list_lock);
  25.        
  26.         end:return;
  27.     }
  28.  
  29.  
  30.  
  31. void registerTvlv(uint8_t type,uint8_t version,uint8_t length,uint8_t *value,struct batadv_priv *bat_priv,struct batadv_ogm_packet *ogm){
  32.    
  33.     if(!type || !version || !length || !value || !bat_priv ||!ogm)
  34.     goto end;
  35.    
  36.        
  37.     printk("Type %d version %d length %d \n",type,version,length);
  38.    
  39.    
  40.     struct batadv_shortTvlv_node *shortTvlv_node=0;
  41.     struct hlist_node *listnode=0;;
  42.     int new=0;
  43.     uint8_t *val=0;
  44.  
  45.  
  46.     rcu_read_lock();
  47.        
  48.         hlist_for_each_entry_rcu(shortTvlv_node,listnode,&bat_priv->tvlv_list,tlist){
  49.    
  50.          
  51.          if(shortTvlv_node->sTvlv->type!=type )
  52.          continue;
  53.        
  54.          goto update;
  55.        
  56.          }
  57.  
  58. new:
  59. printk("Constructing new tlv\n");
  60. struct shortTvlv *tvlv=0;
  61. tvlv=kmalloc(sizeof(struct shortTvlv)+sizeof(uint8_t),GFP_KERNEL);
  62.         printk("passed malloc checking for new memory validity\n");
  63.         if(!tvlv)goto end;
  64.         printk("mem valid puting tvl \n");
  65.      tvlv->length=length;
  66.      tvlv->version=version;
  67.      tvlv->type=type;
  68.             printk("tvl filled\n");
  69.      ogm->nofAppendedTvlvs++;
  70.             printk("tvl registered in the ogm\n");
  71.      memcpy(tvlv+sizeof(struct shortTvlv),value,length*sizeof(uint8_t));
  72.             printk("value put in place\n");
  73.      addTvlvNode(bat_priv,tvlv);
  74.            
  75.      printk("New Tvlv added: %d\n",ogm->nofAppendedTvlvs);
  76.      goto end;
  77. update:
  78.     printk("updating existing one\n");
  79.     val=value;
  80.     struct shortTvlv *tmp;
  81.     tmp=shortTvlv_node->sTvlv;
  82.     memcpy(tmp+sizeof(struct shortTvlv),val,length*sizeof(uint8_t));
  83.    
  84. end:
  85.     rcu_read_unlock();
  86.    
  87.         }
Advertisement
Add Comment
Please, Sign In to add comment