Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct shortTvlv {
- uint8_t type;
- uint8_t version;
- uint8_t length;
- };
- struct longTvlv {
- uint8_t type;
- uint8_t version;
- uint16_t length;
- };
- struct batadv_shortTvlv_node {
- struct hlist_node tlist;
- struct rcu_head rcu;
- struct shortTvlv *sTvlv;
- };
- struct batadv_longTvlv_node {
- struct hlist_node tlist;
- struct longTvlv *tvlv;
- struct rcu_head rcu;
- };
- void registerTvlv( uint8_t type,
- uint8_t version,
- uint8_t length,/*i'm not sure we need the length it should be calculable from the value*/
- uint8_t *value,
- struct batadv_priv *bat_priv,
- struct batadv_ogm_packet *ogm);
- void addTvlvNode(struct batadv_priv *bat_priv,struct shortTvlv *tvlv){
- struct batadv_shortTvlv_node *tvlv_node=0;
- if(!bat_priv || !tvlv)
- goto end;
- tvlv_node=kmalloc(sizeof(struct batadv_shortTvlv_node), GFP_KERNEL);
- printk("New node allocated\n");
- if (!tvlv_node)
- return;
- INIT_HLIST_NODE(&tvlv_node->tlist);
- printk("New node inited\n");
- spin_lock_bh(&bat_priv->tvlv_list_lock);
- tvlv_node->sTvlv=tvlv;
- printk("New node assigned\n");
- hlist_add_head_rcu(&tvlv_node->tlist, &bat_priv->tvlv_list);
- printk("New node put in list\n");
- spin_unlock_bh(&bat_priv->tvlv_list_lock);
- end:return;
- }
- void registerTvlv(uint8_t type,uint8_t version,uint8_t length,uint8_t *value,struct batadv_priv *bat_priv,struct batadv_ogm_packet *ogm){
- if(!type || !version || !length || !value || !bat_priv ||!ogm)
- goto end;
- printk("Type %d version %d length %d \n",type,version,length);
- struct batadv_shortTvlv_node *shortTvlv_node=0;
- struct hlist_node *listnode=0;;
- int new=0;
- uint8_t *val=0;
- rcu_read_lock();
- hlist_for_each_entry_rcu(shortTvlv_node,listnode,&bat_priv->tvlv_list,tlist){
- if(shortTvlv_node->sTvlv->type!=type )
- continue;
- goto update;
- }
- new:
- printk("Constructing new tlv\n");
- struct shortTvlv *tvlv=0;
- tvlv=kmalloc(sizeof(struct shortTvlv)+sizeof(uint8_t),GFP_KERNEL);
- printk("passed malloc checking for new memory validity\n");
- if(!tvlv)goto end;
- printk("mem valid puting tvl \n");
- tvlv->length=length;
- tvlv->version=version;
- tvlv->type=type;
- printk("tvl filled\n");
- ogm->nofAppendedTvlvs++;
- printk("tvl registered in the ogm\n");
- memcpy(tvlv+sizeof(struct shortTvlv),value,length*sizeof(uint8_t));
- printk("value put in place\n");
- addTvlvNode(bat_priv,tvlv);
- printk("New Tvlv added: %d\n",ogm->nofAppendedTvlvs);
- goto end;
- update:
- printk("updating existing one\n");
- val=value;
- struct shortTvlv *tmp;
- tmp=shortTvlv_node->sTvlv;
- memcpy(tmp+sizeof(struct shortTvlv),val,length*sizeof(uint8_t));
- end:
- rcu_read_unlock();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement