Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ovpn: pktid: use bitops.h API

Use bitops.h for replay window to simplify code.

Signed-off-by: Qingfang Deng <dqfext@gmail.com>
[antonio@openvpn.net: extended commit message]
Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
Reviewed-by: Sabrina Dubroca <sd@queasysnail.net>

authored by

Qingfang Deng and committed by
Antonio Quartulli
4a648059 7e7ca01d

+5 -8
+4 -7
drivers/net/ovpn/pktid.c
··· 65 65 if (likely(pkt_id == pr->id + 1)) { 66 66 /* well-formed ID sequence (incremented by 1) */ 67 67 pr->base = REPLAY_INDEX(pr->base, -1); 68 - pr->history[pr->base / 8] |= (1 << (pr->base % 8)); 68 + __set_bit(pr->base, pr->history); 69 69 if (pr->extent < REPLAY_WINDOW_SIZE) 70 70 ++pr->extent; 71 71 pr->id = pkt_id; ··· 77 77 unsigned int i; 78 78 79 79 pr->base = REPLAY_INDEX(pr->base, -delta); 80 - pr->history[pr->base / 8] |= (1 << (pr->base % 8)); 80 + __set_bit(pr->base, pr->history); 81 81 pr->extent += delta; 82 82 if (pr->extent > REPLAY_WINDOW_SIZE) 83 83 pr->extent = REPLAY_WINDOW_SIZE; 84 84 for (i = 1; i < delta; ++i) { 85 85 unsigned int newb = REPLAY_INDEX(pr->base, i); 86 86 87 - pr->history[newb / 8] &= ~BIT(newb % 8); 87 + __clear_bit(newb, pr->history); 88 88 } 89 89 } else { 90 90 pr->base = 0; ··· 103 103 if (pkt_id > pr->id_floor) { 104 104 const unsigned int ri = REPLAY_INDEX(pr->base, 105 105 delta); 106 - u8 *p = &pr->history[ri / 8]; 107 - const u8 mask = (1 << (ri % 8)); 108 106 109 - if (*p & mask) { 107 + if (__test_and_set_bit(ri, pr->history)) { 110 108 ret = -EINVAL; 111 109 goto out; 112 110 } 113 - *p |= mask; 114 111 } else { 115 112 ret = -EINVAL; 116 113 goto out;
+1 -1
drivers/net/ovpn/pktid.h
··· 34 34 */ 35 35 struct ovpn_pktid_recv { 36 36 /* "sliding window" bitmask of recent packet IDs received */ 37 - u8 history[REPLAY_WINDOW_BYTES]; 37 + DECLARE_BITMAP(history, REPLAY_WINDOW_SIZE); 38 38 /* bit position of deque base in history */ 39 39 unsigned int base; 40 40 /* extent (in bits) of deque in history */