proto: revisit short-circuit loops over upper protocols
Pablo Neira Ayuso
maintainerPATCH 1/1 proto: revisit short-circuit loops over upper protocols
Move the check for NULL protocol description away from the loop to avoid too long line.
Signed-off-by Pablo Neira Ayuso <[email protected]>
--- src/proto.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
src/proto.c +9 -7
@@ -59,8 +59,9 @@ proto_find_upper(const struct proto_desc *base, unsigned int num) {unsigned int i; -for (i =0 ; i <array_size (base->protocols) && base->protocols[i].desc; - i++) { +for (i =0 ; i <array_size (base->protocols); i++) { +if (!base->protocols[i].desc) +break ;if (base->protocols[i].num == num)return base->protocols[i].desc; }
@@ -78,8 +79,9 @@ int proto_find_num(const struct proto_desc *base, {unsigned int i; -for (i =0 ; i <array_size (base->protocols) && base->protocols[i].desc; - i++) { +for (i =0 ; i <array_size (base->protocols); i++) { +if (!base->protocols[i].desc) +break ;if (base->protocols[i].desc == desc)return base->protocols[i].num; }
@@ -107,9 +109,9 @@ int proto_dev_type(const struct proto_desc *desc, uint16_t *res) *res = dev_proto_desc[i].type;return 0 ; } -for (j =0 ; j <array_size (base->protocols) && - base->protocols[j].desc; - j++) { +for (j =0 ; j <array_size (base->protocols); j++) { +if (!base->protocols[j].desc) +break ;if (base->protocols[j].desc == desc) { *res = dev_proto_desc[i].type;return 0 ;
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 1/1 tests: shell: extend catchall tests for maps
Add a few tests for the catchall features and maps.
Signed-off-by Pablo Neira Ayuso <[email protected]>
--- tests/shell/testcases/sets/0064map_catchall_0 | 5 +++++ tests/shell/testcases/sets/dumps/0064map_catchall_0.nft | 6 ++++++ 2 files changed, 11 insertions(+)
tests/shell/testcases/sets/0064map_catchall_0 +5 -0
@@ -17,3 +17,8 @@ RULESET="table ip x { $NFT -f - <<< $RULESET $NFT delete element x y { \* : 192.168.0.3 } $NFT add element x y { \* : 192.168.0.4 } + +$NFT add chain x y +$NFT add rule x y snat to ip saddr map @z +$NFT 'add rule x y snat to ip saddr map { 10.141.0.0/24 : 192.168.0.2, * : 192.168.0.3 }' +$NFT 'add rule x y snat to ip saddr . ip daddr map { 10.141.0.0/24 . 10.0.0.0/8 : 192.168.0.2, 192.168.9.0/24 . 192.168.10.0/24 : 192.168.0.4, * : 192.168.0.3 }'
tests/shell/testcases/sets/dumps/0064map_catchall_0.nft +6 -0
@@ -9,4 +9,10 @@ table ip x { flags interval elements = { 10.141.0.0/24 : 192.168.0.2, * : 192.168.0.3 } } + + chain y { + snat to ip saddr map @z + snat to ip saddr map { 10.141.0.0/24 : 192.168.0.2, * : 192.168.0.3 } + snat to ip saddr . ip daddr map { 10.141.0.0/24 . 10.0.0.0/8 : 192.168.0.2, 192.168.9.0/24 . 192.168.10.0/24 : 192.168.0.4, * : 192.168.0.3 } + } }
Signature · 1 line
2.30.2
Quoted 2 lines · Pablo Neira Ayuso
Move the check for NULL protocol description away from the loop to avoid too long line.
LGTM.
J.
Quoted 51 lines
Signed-off-by Pablo Neira Ayuso <[email protected]>--- src/proto.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)src/proto.c +9
-8@@ -59,8 +59,9 @@ proto_find_upper(const struct proto_desc *base, unsigned int num) {unsigned int i; -for (i =0 ; i <array_size (base->protocols) && base->protocols[i].desc; - i++) { +for (i =0 ; i <array_size (base->protocols); i++) { +if (!base->protocols[i].desc) +break ;if (base->protocols[i].num == num)return base->protocols[i].desc; }@@ -78,8 +79,9 @@ int proto_find_num(const struct proto_desc *base, {unsigned int i; -for (i =0 ; i <array_size (base->protocols) && base->protocols[i].desc; - i++) { +for (i =0 ; i <array_size (base->protocols); i++) { +if (!base->protocols[i].desc) +break ;if (base->protocols[i].desc == desc)return base->protocols[i].num; }@@ -107,9 +109,9 @@ int proto_dev_type(const struct proto_desc *desc, uint16_t *res) *res = dev_proto_desc[i].type;return 0 ; } -for (j =0 ; j <array_size (base->protocols) && - base->protocols[j].desc; - j++) { +for (j =0 ; j <array_size (base->protocols); j++) { +if (!base->protocols[j].desc) +break ;if (base->protocols[j].desc == desc) { *res = dev_proto_desc[i].type;return 0 ; --2.30.2