Advertisement
Guest User

Untitled

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