diff options
Diffstat (limited to 'test/pf_route_freebsd_SUITE.erl')
-rw-r--r-- | test/pf_route_freebsd_SUITE.erl | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/test/pf_route_freebsd_SUITE.erl b/test/pf_route_freebsd_SUITE.erl new file mode 100644 index 0000000..7bb7e1f --- /dev/null +++ b/test/pf_route_freebsd_SUITE.erl @@ -0,0 +1,110 @@ +-module(pf_route_freebsd_SUITE). +-compile(export_all). +-compile(nowarn_export_all). +-include_lib("pf_route/src/pf_route.hrl"). +-include_lib("pf_route/src/pf_route_freebsd.hrl"). +-include_lib("stdlib/include/assert.hrl"). + +suite() -> + [{timetrap, 10000}]. + +all() -> + [{group, pf_route_parser}, {group, netstat_parser}]. + +groups() -> + [{pf_route_parser, [parallel], pf_route_parser_tests()}, {netstat_parser, [parallel], netstat_parser_tests()}]. + +init_per_group(_Group, Config) -> + Config. + +end_per_group(_, _) -> + ok. + +%% Netstat + +netstat_parser_tests() -> + [netstat_list]. + +netstat_list(_) -> + {skip, todo}. + +%% Packet + +pf_route_parser_tests() -> + [pckt_rt_add, pckt_rt_delete, pckt_rt_get, pckt_rt_get_default]. + +pckt_rt_add(_) -> + ct:comment("Simple RT_ADD"), + Binary = <<5,1,3,0,0,0,67,8,0,0,7,0,0,0,14,32,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,2,0,0,192,168,168,0,0,0,0,0,0,0,0,0,16, + 2,0,0,192,168,1,1,0,0,0,0,0,0,0,0,16,2,0,0,255,255,255,0,0,0,0,0,0,0,0, + 0>>, + Rt = pf_route_freebsd:parse_pf_route_packet(Binary), + ?assertEqual(add, Rt#freebsd_rt.type), + ?assertEqual([up, gateway, done, static], Rt#freebsd_rt.flags), + ?assertEqual([destination, gateway, netmask], Rt#freebsd_rt.addrs), + ?assertEqual(73742, Rt#freebsd_rt.pid), + ?assertEqual(1, Rt#freebsd_rt.seq), + ?assertEqual({192, 168, 168, 0}, Rt#freebsd_rt.destination), + ?assertEqual({255, 255, 255, 0}, Rt#freebsd_rt.netmask), + ?assertEqual({192, 168, 1, 1}, Rt#freebsd_rt.gateway), + ?assertEqual(3, Rt#freebsd_rt.ifp_index). + +pckt_rt_delete(_) -> + ct:comment("Simple RT_DELETE"), + Binary = <<5,2,3,0,0,0,66,8,0,0,7,0,0,0,82,33,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,220,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,2,0,0,192,168,168,0,0,0,0,0,0,0,0,0, + 16,2,0,0,192,168,1,1,0,0,0,0,0,0,0,0,16,2,0,0,255,255,255,0,0,0,0,0,0, + 0,0,0>>, + Rt = pf_route_freebsd:parse_pf_route_packet(Binary), + ?assertEqual(delete, Rt#freebsd_rt.type), + ?assertEqual([gateway, done, static], Rt#freebsd_rt.flags), + ?assertEqual([destination, gateway, netmask], Rt#freebsd_rt.addrs), + ?assertEqual(74066, Rt#freebsd_rt.pid), + ?assertEqual(1, Rt#freebsd_rt.seq), + ?assertEqual({192, 168, 168, 0}, Rt#freebsd_rt.destination), + ?assertEqual({255, 255, 255, 0}, Rt#freebsd_rt.netmask), + ?assertEqual({192, 168, 1, 1}, Rt#freebsd_rt.gateway), + ?assertEqual(3, Rt#freebsd_rt.ifp_index). + +pckt_rt_get(_) -> + ct:comment("RT_GET"), + Binary = <<5,4,3,0,0,0,65,0,16,0,55,0,0,0,62,56,1,0,1,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,220,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,2,0,0,192,168,1,0,0,0,0,0,0,0,0,0, + 16,18,3,0,6,0,0,0,0,0,0,0,0,0,0,0,16,2,0,0,255,255,255,0,0,0,0,0,0,0,0, + 0,56,18,3,0,6,5,6,0,108,111,99,97,108,10,96,213,0,0,0,10,96,213,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,2,0,0, + 192,168,1,7,0,0,0,0,0,0,0,0>>, + Rt = pf_route_freebsd:parse_pf_route_packet(Binary), + ?assertEqual(get, Rt#freebsd_rt.type), + {skip, todo}. + +pckt_rt_get_default(_) -> + ct:comment("RT_GET default"), + Binary = <<5,4,5,0,0,0,67,8,0,0,55,0,0,0,254,59,1,0,1,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,120,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,9,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,2,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,16,2,0,0,45,150,148,1,0,0,0,0,0,0,0,0,16,2,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,56,18,5,0,6,7,6,0,97,115,52,51,48,54,57,2,96,213,16,21,42, + 213,16,21,42,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,16,2,0,0,45,150,148,7,0,0,0,0,0,0,0,0>>, + Rt = pf_route_freebsd:parse_pf_route_packet(Binary), + ?assertEqual(get, Rt#freebsd_rt.type), + ?assertEqual([up, gateway, done, static], Rt#freebsd_rt.flags), + ?assertEqual([destination, gateway, netmask, ifp, ifa], Rt#freebsd_rt.addrs), + ?assertEqual(1400, Rt#freebsd_rt.mtu), + ?assertEqual({0, 0, 0, 0}, Rt#freebsd_rt.destination), + ?assertEqual({0, 0, 0, 0}, Rt#freebsd_rt.netmask), + ?assertEqual({45, 150, 148, 1}, Rt#freebsd_rt.gateway), + ?assertEqual(5, Rt#freebsd_rt.ifp_index). |