ipfw: add eaction tests

MFC after:	2 weeks
This commit is contained in:
Alexander V. Chernikov 2023-06-15 06:36:16 +00:00
parent 32b28e3ae2
commit 84b41342da
2 changed files with 39 additions and 0 deletions

View file

@ -173,6 +173,39 @@ def verify_rule(self, in_data: str, out_data):
},
id="test_comment",
),
pytest.param(
{
"in": "add tcp-setmss 123 ip from any to 1.2.3.4",
"out": {
"objs": [
NTlv(IpFwTlvType.IPFW_TLV_EACTION, idx=1, name="tcp-setmss"),
],
"insns": [
InsnIp(IpFwOpcode.O_IP_DST, ip="1.2.3.4"),
Insn(IpFwOpcode.O_EXTERNAL_ACTION, arg1=1),
Insn(IpFwOpcode.O_EXTERNAL_DATA, arg1=123),
],
},
},
id="test_eaction_tcp-setmss",
),
pytest.param(
{
"in": "add eaction ntpv6 AAA ip from any to 1.2.3.4",
"out": {
"objs": [
NTlv(IpFwTlvType.IPFW_TLV_EACTION, idx=1, name="ntpv6"),
NTlv(0, idx=2, name="AAA"),
],
"insns": [
InsnIp(IpFwOpcode.O_IP_DST, ip="1.2.3.4"),
Insn(IpFwOpcode.O_EXTERNAL_ACTION, arg1=1),
Insn(IpFwOpcode.O_EXTERNAL_INSTANCE, arg1=2),
],
},
},
id="test_eaction_ntp",
),
],
)
def test_add_rule(self, rule):

View file

@ -90,6 +90,11 @@ def print_obj(self, prepend=""):
for obj in self.obj_list:
obj.print_obj(prepend)
def print_obj_hex(self, prepend=""):
print(prepend)
print()
print(" ".join(["x{:02X}".format(b) for b in bytes(self)]))
@classmethod
def _validate(cls, data):
if len(data) < sizeof(IpFwObjTlv):
@ -487,6 +492,7 @@ def print_as_bytes(data: bytes, descr: str):
[
AttrDescr(IpFwTlvType.IPFW_TLV_TBL_NAME, NTlv),
AttrDescr(IpFwTlvType.IPFW_TLV_STATE_NAME, NTlv),
AttrDescr(IpFwTlvType.IPFW_TLV_EACTION, NTlv),
],
True,
),