Advertisement
Guest User

Untitled

a guest
Sep 4th, 2013
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.14 KB | None | 0 0
  1. static int tcp_metrics_nl_cmd_add(struct sk_buff *skb, struct genl_info *info)
  2. {
  3.     struct inetpeer_addr addr;
  4.     struct net *net = genl_info_net(info);
  5.     struct tcp_metrics_block *tm;
  6.     unsigned int hash;
  7.     int nla_rem;
  8.  
  9.     struct nlattr *nla;
  10.  
  11.     printk("ADDING TCP METRIC !\n");
  12.  
  13.     // Get the address
  14.     if (parse_nl_addr(info, &addr, &hash, 1) < 0) {
  15.         printk("Error getting address hash.\n");
  16.         return 0;
  17.     }
  18.  
  19.     // Calculate the entry hash
  20.     printk("calculating hash\n");
  21.     hash = hash_32(hash, net->ipv4.tcp_metrics_hash_log);
  22.  
  23.     rcu_read_lock();
  24.     spin_lock_bh(&tcp_metrics_lock);
  25.     tm = __tcp_get_metrics(&addr, net, hash);
  26.  
  27.     if (tm == NULL) {
  28.         printk("Entry doesn't exist create a new one\n");
  29.         printk("Got the lock\n");
  30.         tm = kmalloc(sizeof(*tm), GFP_ATOMIC);
  31.         tm->tcpm_addr = addr;
  32.  
  33.         // Set the default values
  34.         printk("setting default values\n");
  35.         tm->tcpm_vals[TCP_METRIC_RTT] = 0;
  36.         tm->tcpm_vals[TCP_METRIC_RTTVAR] = 0;
  37.         tm->tcpm_vals[TCP_METRIC_SSTHRESH] = 0;
  38.         tm->tcpm_vals[TCP_METRIC_CWND] = 0;
  39.         tm->tcpm_vals[TCP_METRIC_REORDERING] = 0;
  40.         tm->tcpm_ts = 0;
  41.         tm->tcpm_ts_stamp = 0;
  42.         tm->tcpm_fastopen.mss = 0;
  43.         tm->tcpm_fastopen.syn_loss = 0;
  44.         tm->tcpm_fastopen.cookie.len = 0;
  45.  
  46.         // Add the entry to the hashtable
  47.         printk("adding entry to hashtable\n");
  48.         tm->tcpm_next = net->ipv4.tcp_metrics_hash[hash].chain;
  49.         printk("assigning pointer\n");
  50.         rcu_assign_pointer(net->ipv4.tcp_metrics_hash[hash].chain, tm);
  51.     } else {
  52.         printk("Updating existing entry\n");
  53.     }
  54.  
  55.     printk("updating jiffies\n");
  56.     tm->tcpm_stamp = jiffies;
  57.  
  58.     // Read the metrics from the incoming packet
  59.     printk("reading attributes\n");
  60.     nla_for_each_nested(nla, info->attrs[TCP_METRICS_ATTR_VALS], nla_rem) {
  61.         printk("metric %d = %d\n", nla_type(nla), nla_get_u32(nla));
  62.         tm->tcpm_vals[nla_type(nla) - 1] = nla_get_u32(nla);
  63.     }
  64.  
  65.     printk("unlock\n");
  66.     spin_unlock_bh(&tcp_metrics_lock);
  67.  
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement