@@ -25,6 +25,7 @@ struct nft_limit {
2525 u64 tokens_max ;
2626 u64 rate ;
2727 u64 nsecs ;
28+ u32 burst ;
2829};
2930
3031static inline bool nft_limit_eval (struct nft_limit * limit , u64 cost )
@@ -65,6 +66,18 @@ static int nft_limit_init(struct nft_limit *limit,
6566 if (limit -> rate == 0 || limit -> nsecs < unit )
6667 return - EOVERFLOW ;
6768 limit -> tokens = limit -> tokens_max = limit -> nsecs ;
69+
70+ if (tb [NFTA_LIMIT_BURST ]) {
71+ u64 rate ;
72+
73+ limit -> burst = ntohl (nla_get_be32 (tb [NFTA_LIMIT_BURST ]));
74+
75+ rate = limit -> rate + limit -> burst ;
76+ if (rate < limit -> rate )
77+ return - EOVERFLOW ;
78+
79+ limit -> rate = rate ;
80+ }
6881 limit -> last = ktime_get_ns ();
6982
7083 return 0 ;
@@ -73,9 +86,11 @@ static int nft_limit_init(struct nft_limit *limit,
7386static int nft_limit_dump (struct sk_buff * skb , const struct nft_limit * limit )
7487{
7588 u64 secs = div_u64 (limit -> nsecs , NSEC_PER_SEC );
89+ u64 rate = limit -> rate - limit -> burst ;
7690
77- if (nla_put_be64 (skb , NFTA_LIMIT_RATE , cpu_to_be64 (limit -> rate )) ||
78- nla_put_be64 (skb , NFTA_LIMIT_UNIT , cpu_to_be64 (secs )))
91+ if (nla_put_be64 (skb , NFTA_LIMIT_RATE , cpu_to_be64 (rate )) ||
92+ nla_put_be64 (skb , NFTA_LIMIT_UNIT , cpu_to_be64 (secs )) ||
93+ nla_put_be32 (skb , NFTA_LIMIT_BURST , htonl (limit -> burst )))
7994 goto nla_put_failure ;
8095 return 0 ;
8196
@@ -96,6 +111,7 @@ static void nft_limit_pkts_eval(const struct nft_expr *expr,
96111static const struct nla_policy nft_limit_policy [NFTA_LIMIT_MAX + 1 ] = {
97112 [NFTA_LIMIT_RATE ] = { .type = NLA_U64 },
98113 [NFTA_LIMIT_UNIT ] = { .type = NLA_U64 },
114+ [NFTA_LIMIT_BURST ] = { .type = NLA_U32 },
99115};
100116
101117static int nft_limit_pkts_init (const struct nft_ctx * ctx ,
0 commit comments