act_csum.c (8c57a5e7b2820f349c95b8c8393fec1e0f4070d2) | act_csum.c (a85a970af265f156740977168b542234511b28a8) |
---|---|
1/* 2 * Checksum updating actions 3 * 4 * Copyright (c) 2010 Gregoire Baron <baronchon@n7mm.org> 5 * 6 * This program is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License as published by the Free 8 * Software Foundation; either version 2 of the License, or (at your option) --- 29 unchanged lines hidden (view full) --- 38 39#define CSUM_TAB_MASK 15 40 41static const struct nla_policy csum_policy[TCA_CSUM_MAX + 1] = { 42 [TCA_CSUM_PARMS] = { .len = sizeof(struct tc_csum), }, 43}; 44 45static int csum_net_id; | 1/* 2 * Checksum updating actions 3 * 4 * Copyright (c) 2010 Gregoire Baron <baronchon@n7mm.org> 5 * 6 * This program is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License as published by the Free 8 * Software Foundation; either version 2 of the License, or (at your option) --- 29 unchanged lines hidden (view full) --- 38 39#define CSUM_TAB_MASK 15 40 41static const struct nla_policy csum_policy[TCA_CSUM_MAX + 1] = { 42 [TCA_CSUM_PARMS] = { .len = sizeof(struct tc_csum), }, 43}; 44 45static int csum_net_id; |
46static struct tc_action_ops act_csum_ops; |
|
46 47static int tcf_csum_init(struct net *net, struct nlattr *nla, | 47 48static int tcf_csum_init(struct net *net, struct nlattr *nla, |
48 struct nlattr *est, struct tc_action *a, int ovr, | 49 struct nlattr *est, struct tc_action **a, int ovr, |
49 int bind) 50{ 51 struct tc_action_net *tn = net_generic(net, csum_net_id); 52 struct nlattr *tb[TCA_CSUM_MAX + 1]; 53 struct tc_csum *parm; 54 struct tcf_csum *p; 55 int ret = 0, err; 56 --- 5 unchanged lines hidden (view full) --- 62 return err; 63 64 if (tb[TCA_CSUM_PARMS] == NULL) 65 return -EINVAL; 66 parm = nla_data(tb[TCA_CSUM_PARMS]); 67 68 if (!tcf_hash_check(tn, parm->index, a, bind)) { 69 ret = tcf_hash_create(tn, parm->index, est, a, | 50 int bind) 51{ 52 struct tc_action_net *tn = net_generic(net, csum_net_id); 53 struct nlattr *tb[TCA_CSUM_MAX + 1]; 54 struct tc_csum *parm; 55 struct tcf_csum *p; 56 int ret = 0, err; 57 --- 5 unchanged lines hidden (view full) --- 63 return err; 64 65 if (tb[TCA_CSUM_PARMS] == NULL) 66 return -EINVAL; 67 parm = nla_data(tb[TCA_CSUM_PARMS]); 68 69 if (!tcf_hash_check(tn, parm->index, a, bind)) { 70 ret = tcf_hash_create(tn, parm->index, est, a, |
70 sizeof(*p), bind, false); | 71 &act_csum_ops, bind, false); |
71 if (ret) 72 return ret; 73 ret = ACT_P_CREATED; 74 } else { 75 if (bind)/* dont override defaults */ 76 return 0; | 72 if (ret) 73 return ret; 74 ret = ACT_P_CREATED; 75 } else { 76 if (bind)/* dont override defaults */ 77 return 0; |
77 tcf_hash_release(a, bind); | 78 tcf_hash_release(*a, bind); |
78 if (!ovr) 79 return -EEXIST; 80 } 81 | 79 if (!ovr) 80 return -EEXIST; 81 } 82 |
82 p = to_tcf_csum(a); | 83 p = to_tcf_csum(*a); |
83 spin_lock_bh(&p->tcf_lock); 84 p->tcf_action = parm->action; 85 p->update_flags = parm->update_flags; 86 spin_unlock_bh(&p->tcf_lock); 87 88 if (ret == ACT_P_CREATED) | 84 spin_lock_bh(&p->tcf_lock); 85 p->tcf_action = parm->action; 86 p->update_flags = parm->update_flags; 87 spin_unlock_bh(&p->tcf_lock); 88 89 if (ret == ACT_P_CREATED) |
89 tcf_hash_insert(tn, a); | 90 tcf_hash_insert(tn, *a); |
90 91 return ret; 92} 93 94/** 95 * tcf_csum_skb_nextlayer - Get next layer pointer 96 * @skb: sk_buff to use 97 * @ihl: previous summed headers length --- 393 unchanged lines hidden (view full) --- 491 492fail: 493 return 0; 494} 495 496static int tcf_csum(struct sk_buff *skb, 497 const struct tc_action *a, struct tcf_result *res) 498{ | 91 92 return ret; 93} 94 95/** 96 * tcf_csum_skb_nextlayer - Get next layer pointer 97 * @skb: sk_buff to use 98 * @ihl: previous summed headers length --- 393 unchanged lines hidden (view full) --- 492 493fail: 494 return 0; 495} 496 497static int tcf_csum(struct sk_buff *skb, 498 const struct tc_action *a, struct tcf_result *res) 499{ |
499 struct tcf_csum *p = a->priv; | 500 struct tcf_csum *p = to_tcf_csum(a); |
500 int action; 501 u32 update_flags; 502 503 spin_lock(&p->tcf_lock); | 501 int action; 502 u32 update_flags; 503 504 spin_lock(&p->tcf_lock); |
504 p->tcf_tm.lastuse = jiffies; | 505 tcf_lastuse_update(&p->tcf_tm); |
505 bstats_update(&p->tcf_bstats, skb); 506 action = p->tcf_action; 507 update_flags = p->update_flags; 508 spin_unlock(&p->tcf_lock); 509 510 if (unlikely(action == TC_ACT_SHOT)) 511 goto drop; 512 --- 16 unchanged lines hidden (view full) --- 529 spin_unlock(&p->tcf_lock); 530 return TC_ACT_SHOT; 531} 532 533static int tcf_csum_dump(struct sk_buff *skb, 534 struct tc_action *a, int bind, int ref) 535{ 536 unsigned char *b = skb_tail_pointer(skb); | 506 bstats_update(&p->tcf_bstats, skb); 507 action = p->tcf_action; 508 update_flags = p->update_flags; 509 spin_unlock(&p->tcf_lock); 510 511 if (unlikely(action == TC_ACT_SHOT)) 512 goto drop; 513 --- 16 unchanged lines hidden (view full) --- 530 spin_unlock(&p->tcf_lock); 531 return TC_ACT_SHOT; 532} 533 534static int tcf_csum_dump(struct sk_buff *skb, 535 struct tc_action *a, int bind, int ref) 536{ 537 unsigned char *b = skb_tail_pointer(skb); |
537 struct tcf_csum *p = a->priv; | 538 struct tcf_csum *p = to_tcf_csum(a); |
538 struct tc_csum opt = { 539 .update_flags = p->update_flags, 540 .index = p->tcf_index, 541 .action = p->tcf_action, 542 .refcnt = p->tcf_refcnt - ref, 543 .bindcnt = p->tcf_bindcnt - bind, 544 }; 545 struct tcf_t t; 546 547 if (nla_put(skb, TCA_CSUM_PARMS, sizeof(opt), &opt)) 548 goto nla_put_failure; | 539 struct tc_csum opt = { 540 .update_flags = p->update_flags, 541 .index = p->tcf_index, 542 .action = p->tcf_action, 543 .refcnt = p->tcf_refcnt - ref, 544 .bindcnt = p->tcf_bindcnt - bind, 545 }; 546 struct tcf_t t; 547 548 if (nla_put(skb, TCA_CSUM_PARMS, sizeof(opt), &opt)) 549 goto nla_put_failure; |
549 t.install = jiffies_to_clock_t(jiffies - p->tcf_tm.install); 550 t.lastuse = jiffies_to_clock_t(jiffies - p->tcf_tm.lastuse); 551 t.expires = jiffies_to_clock_t(p->tcf_tm.expires); 552 if (nla_put(skb, TCA_CSUM_TM, sizeof(t), &t)) | 550 551 tcf_tm_dump(&t, &p->tcf_tm); 552 if (nla_put_64bit(skb, TCA_CSUM_TM, sizeof(t), &t, TCA_CSUM_PAD)) |
553 goto nla_put_failure; 554 555 return skb->len; 556 557nla_put_failure: 558 nlmsg_trim(skb, b); 559 return -1; 560} 561 562static int tcf_csum_walker(struct net *net, struct sk_buff *skb, 563 struct netlink_callback *cb, int type, | 553 goto nla_put_failure; 554 555 return skb->len; 556 557nla_put_failure: 558 nlmsg_trim(skb, b); 559 return -1; 560} 561 562static int tcf_csum_walker(struct net *net, struct sk_buff *skb, 563 struct netlink_callback *cb, int type, |
564 struct tc_action *a) | 564 const struct tc_action_ops *ops) |
565{ 566 struct tc_action_net *tn = net_generic(net, csum_net_id); 567 | 565{ 566 struct tc_action_net *tn = net_generic(net, csum_net_id); 567 |
568 return tcf_generic_walker(tn, skb, cb, type, a); | 568 return tcf_generic_walker(tn, skb, cb, type, ops); |
569} 570 | 569} 570 |
571static int tcf_csum_search(struct net *net, struct tc_action *a, u32 index) | 571static int tcf_csum_search(struct net *net, struct tc_action **a, u32 index) |
572{ 573 struct tc_action_net *tn = net_generic(net, csum_net_id); 574 575 return tcf_hash_search(tn, a, index); 576} 577 578static struct tc_action_ops act_csum_ops = { 579 .kind = "csum", 580 .type = TCA_ACT_CSUM, 581 .owner = THIS_MODULE, 582 .act = tcf_csum, 583 .dump = tcf_csum_dump, 584 .init = tcf_csum_init, 585 .walk = tcf_csum_walker, 586 .lookup = tcf_csum_search, | 572{ 573 struct tc_action_net *tn = net_generic(net, csum_net_id); 574 575 return tcf_hash_search(tn, a, index); 576} 577 578static struct tc_action_ops act_csum_ops = { 579 .kind = "csum", 580 .type = TCA_ACT_CSUM, 581 .owner = THIS_MODULE, 582 .act = tcf_csum, 583 .dump = tcf_csum_dump, 584 .init = tcf_csum_init, 585 .walk = tcf_csum_walker, 586 .lookup = tcf_csum_search, |
587 .size = sizeof(struct tcf_csum), |
|
587}; 588 589static __net_init int csum_init_net(struct net *net) 590{ 591 struct tc_action_net *tn = net_generic(net, csum_net_id); 592 593 return tc_action_net_init(tn, &act_csum_ops, CSUM_TAB_MASK); 594} --- 30 unchanged lines hidden --- | 588}; 589 590static __net_init int csum_init_net(struct net *net) 591{ 592 struct tc_action_net *tn = net_generic(net, csum_net_id); 593 594 return tc_action_net_init(tn, &act_csum_ops, CSUM_TAB_MASK); 595} --- 30 unchanged lines hidden --- |