blob: 6460dcf9a0169e66d63ea1b62eb9f7e040c44767 [file] [log] [blame]
Junyu Lai32a2d152024-07-03 16:05:41 +08001# Copyright (C) 2024 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
Junyu Lai94186342024-08-23 23:09:43 +080015from absl.testing import parameterized
Junyu Lai6f6b1a42024-07-04 15:34:30 +080016from net_tests_utils.host.python import apf_test_base
Junyu Lai32a2d152024-07-03 16:05:41 +080017
Junyu Lai6f6b1a42024-07-04 15:34:30 +080018# Constants.
Junyu Lai32a2d152024-07-03 16:05:41 +080019COUNTER_DROPPED_ETHERTYPE_NOT_ALLOWED = "DROPPED_ETHERTYPE_NOT_ALLOWED"
Junyu Lai6f6b1a42024-07-04 15:34:30 +080020ETHER_BROADCAST_ADDR = "FFFFFFFFFFFF"
Junyu Lai32a2d152024-07-03 16:05:41 +080021
22
Junyu Lai94186342024-08-23 23:09:43 +080023class ApfV4Test(apf_test_base.ApfTestBase, parameterized.TestCase):
Junyu Lai32a2d152024-07-03 16:05:41 +080024
Junyu Lai94186342024-08-23 23:09:43 +080025 # APF L2 packet filtering on V+ Android allows only specific
26 # types: IPv4, ARP, IPv6, EAPOL, WAPI.
27 # Tests can use any disallowed packet type. Currently,
28 # several ethertypes from the legacy ApfFilter denylist are used.
29 @parameterized.parameters(
30 "88a2", # ATA over Ethernet
31 "88a4", # EtherCAT
32 "88b8", # GOOSE (Generic Object Oriented Substation event)
33 "88cd", # SERCOS III
34 "88e3", # Media Redundancy Protocol (IEC62439-2)
35 ) # Declare inputs for state_str and expected_result.
36 def test_apf_drop_ethertype_not_allowed(self, blocked_ether_type):
Junyu Lai6f6b1a42024-07-04 15:34:30 +080037 # Ethernet header (14 bytes).
38 packet = ETHER_BROADCAST_ADDR # Destination MAC (broadcast)
39 packet += self.server_mac_address.replace(":", "") # Source MAC
Junyu Lai94186342024-08-23 23:09:43 +080040 packet += blocked_ether_type
Junyu Lai32a2d152024-07-03 16:05:41 +080041
Junyu Lai94186342024-08-23 23:09:43 +080042 # Pad with zeroes to minimum ethernet frame length.
Junyu Lai6f6b1a42024-07-04 15:34:30 +080043 packet += "00" * 46
44 self.send_packet_and_expect_counter_increased(
45 packet, COUNTER_DROPPED_ETHERTYPE_NOT_ALLOWED
Junyu Laicf655862024-07-04 11:09:52 +080046 )