1. Include copyright headers in all files.
2. Clean up all lint messages except "bad header", which doesn't
like our copyright statement, but which I do not seem to be
able to disable.
Change-Id: I33b44eb7f942f0ce03c001e674377f193fb66def
+# Copyright 2014 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
"""A simple module for declaring C-like structures.
Example usage:
#!/usr/bin/python
+#
+# Copyright 2014 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
"""Partial Python implementation of iproute functionality."""
#!/usr/bin/python
+#
+# Copyright 2014 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Base module for multinetwork tests."""
import errno
import fcntl
In6Pktinfo = cstruct.Struct("in6_pktinfo", "@16si", "addr ifindex")
-# Check to see if the kernel supports UID routing.
def HaveUidRouting():
+ """Checks whether the kernel supports UID routing."""
# Create a rule with the UID range selector. If the kernel doesn't understand
# the selector, it will create a rule with no selectors.
try:
class MultiNetworkBaseTest(net_test.NetworkTest):
+ """Base class for all multinetwork tests.
+
+ This class does not contain any test code, but contains code to set up and
+ tear a multi-network environment using multiple tun interfaces. The
+ environment is designed to be similar to a real Android device in terms of
+ rules and routes, and supports IPv4 and IPv6.
+
+ Tests wishing to use this environment should inherit from this class and
+ ensure that any setupClass, tearDownClass, setUp, and tearDown methods they
+ implement also call the superclass versions.
+ """
+
# Must be between 1 and 256, since we put them in MAC addresses and IIDs.
NETIDS = [100, 150, 200, 250]
while True:
try:
packet = posix.read(self.tuns[netid].fileno(), 4096)
- if len(packet) == 0:
+ if not packet:
break
ether = scapy.Ether(packet)
# Multicast frames are frames where the first byte of the destination
#!/usr/bin/python
+#
+# Copyright 2014 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
import errno
import os
#!/usr/bin/python
+#
+# Copyright 2014 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
import fcntl
import os
#!/usr/bin/python
+#
+# Copyright 2014 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
# pylint: disable=g-bad-todo
self.assertEquals(written, len(reply))
def testCrossProtocolCrash(self):
-
- def GetIPv4Unreachable(port):
+ # Checks that an ICMP error containing a ping packet that matches the ID
+ # of a socket of the wrong protocol (which can happen when using 464xlat)
+ # doesn't crash the kernel.
+
+ # We can only test this using IPv6 unreachables and IPv4 ping sockets,
+ # because IPv4 packets sent by scapy.send() on loopback are not received by
+ # the kernel. So we don't actually use this function yet.
+ def GetIPv4Unreachable(port): # pylint: disable=unused-variable
return (scapy.IP(src="192.0.2.1", dst="127.0.0.1") /
scapy.ICMP(type=3, code=0) /
scapy.IP(src="127.0.0.1", dst="127.0.0.1") /
scapy.ICMPv6EchoRequest(id=port, seq=1, data="foobarbaz"))
# An unreachable matching the ID of a socket of the wrong protocol
- # shouldn't crash. We can only test this using IPv6 unreachables and IPv4
- # ping sockets, because IPv4 packets sent by scapy.send() on loopback don't
- # appear to be received by the kernel.)
+ # shouldn't crash.
s = net_test.IPv4PingSocket()
s.connect(("127.0.0.1", 12345))
_, port = s.getsockname()
if __name__ == "__main__":
unittest.main()
-
-#!/usr/bin/python
+# Copyright 2014 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
"""Python wrapper for sendmsg."""
#!/usr/bin/python
+#
+# Copyright 2014 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
import errno
import os