Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static int tcp_metrics_nl_cmd_add(struct sk_buff *skb, struct genl_info *info)
- {
- struct inetpeer_addr addr;
- struct net *net = genl_info_net(info);
- struct tcp_metrics_block *tm;
- unsigned int hash;
- int nla_rem;
- struct nlattr *nla;
- printk("ADDING TCP METRIC !\n");
- // Get the address
- if (parse_nl_addr(info, &addr, &hash, 1) < 0) {
- printk("Error getting address hash.\n");
- return 0;
- }
- // Calculate the entry hash
- printk("calculating hash\n");
- hash = hash_32(hash, net->ipv4.tcp_metrics_hash_log);
- rcu_read_lock();
- spin_lock_bh(&tcp_metrics_lock);
- tm = __tcp_get_metrics(&addr, net, hash);
- if (tm == NULL) {
- printk("Entry doesn't exist create a new one\n");
- printk("Got the lock\n");
- tm = kmalloc(sizeof(*tm), GFP_ATOMIC);
- tm->tcpm_addr = addr;
- // Set the default values
- printk("setting default values\n");
- tm->tcpm_vals[TCP_METRIC_RTT] = 0;
- tm->tcpm_vals[TCP_METRIC_RTTVAR] = 0;
- tm->tcpm_vals[TCP_METRIC_SSTHRESH] = 0;
- tm->tcpm_vals[TCP_METRIC_CWND] = 0;
- tm->tcpm_vals[TCP_METRIC_REORDERING] = 0;
- tm->tcpm_ts = 0;
- tm->tcpm_ts_stamp = 0;
- tm->tcpm_fastopen.mss = 0;
- tm->tcpm_fastopen.syn_loss = 0;
- tm->tcpm_fastopen.cookie.len = 0;
- // Add the entry to the hashtable
- printk("adding entry to hashtable\n");
- tm->tcpm_next = net->ipv4.tcp_metrics_hash[hash].chain;
- printk("assigning pointer\n");
- rcu_assign_pointer(net->ipv4.tcp_metrics_hash[hash].chain, tm);
- } else {
- printk("Updating existing entry\n");
- }
- printk("updating jiffies\n");
- tm->tcpm_stamp = jiffies;
- // Read the metrics from the incoming packet
- printk("reading attributes\n");
- nla_for_each_nested(nla, info->attrs[TCP_METRICS_ATTR_VALS], nla_rem) {
- printk("metric %d = %d\n", nla_type(nla), nla_get_u32(nla));
- tm->tcpm_vals[nla_type(nla) - 1] = nla_get_u32(nla);
- }
- printk("unlock\n");
- spin_unlock_bh(&tcp_metrics_lock);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement