HAProxy ACL规则中的64位整数比较 [英] 64 bit integer comparison in HAProxy acl rule

查看:113
本文介绍了HAProxy ACL规则中的64位整数比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下acl规则来检查url_param值的范围.

I have following acl rules to check the range of my url_param value.

acl small       urlp_val(uid) le 311111111111000000
acl medium       urlp_val(uid) 311111111111000001:311111111111001000
acl large       urlp_val(uid) ge 311111111111001001

数字是64位整数.这种比较似乎不起作用.它始终仅重定向到一个实例.如果我将数字减少到1到100的范围内,则效果很好.它不支持64位数字,还是我在这里做愚蠢/愚蠢的事情?

The number are 64 bit integers. This comparison doesn't seem to be working. It always redirect to only one instance. If I decrease the numbers to a range of say 1 to 100, it works well. Does it not support 64 bit numbers or am I doing something stupid/silly here?

推荐答案

我有类似的任务.我通过从大量数字中删除最后6个字符并仅比较第一部分来解决了这个问题.

I am had a similar task. I solved it by cutting off the last 6 characters from a large number and comparing only the first part.

# my case: if some_id >= 9089000000 use backend_2

acl is_number_long urlp_reg('some_id') '^\d{7,}$'
acl is_first_part_great urlp('some_id'),regsub('\d{6}$','') -m int gt 9088

use_backend backend_2 if is_number_long is_first_part_great

default_backend backend_1

您可以尝试以下操作:

# some_id = 311111111111000000 -> first_part = 311111111, last_part = 111000000

acl is_number_long urlp_reg('some_id') '^\d{10,}$'

acl is_first_part_gt urlp('some_id'),regsub('\d{9}$','') -m int gt 311111111
acl is_first_part_eq urlp('some_id'),regsub('\d{9}$','') -m int eq 311111111

acl is_last_part_gt urlp('some_id'),regsub('^.*(\d{9})$','\1') -m int gt 111000000
acl is_last_part_lt urlp('some_id'),regsub('^.*(\d{9})$','\1') -m int lt 111001001

use_backend backend_3 if is_number_long is_first_part_gt                                  # large
use_backend backend_3 if is_number_long is_first_part_eq !is_last_part_lt                 # large

use_backend backend_2 if is_number_long is_first_part_eq is_last_part_gt is_last_part_lt  # medium

default_backend backend_1                                                                 # small

这篇关于HAProxy ACL规则中的64位整数比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆