Commit Graph

272 Commits

Author SHA1 Message Date
Chalard Jean
2ecf120256 Move bit utility methods to a new BitUtils class.
In particular this moves NetworkCapabilies#
appendStringRepresentationOfBitMaskToStringBuilder to this
class. It also moves some other NetworkCapabilitiesUtils
methods that are better homed in this new class.

Test: new test in this patch
Change-Id: I16374d7ca1da92052bb814bde796602d62f5c42e
2022-10-12 20:31:20 +09:00
Junyu Lai
e766a09b79 Merge "[ST02] Add methods for synthesizing DNS packets" 2022-09-22 02:39:42 +00:00
Nucca Chen
48a33adc7b Merge changes from topic "test-tethering-icmp"
* changes:
  IpUtils: add ICMP checksum calculation function
  NetworkStackConstants: add ICMP checksum offset constant
2022-09-19 15:53:43 +00:00
Hungming Chen
0aa70a0973 IpUtils: add ICMP checksum calculation function
Bug: 237369591
Test: NetworkStaticLibTests
Change-Id: If45de190872cad588f9b9104828a0d8116fc158b
2022-09-19 15:34:33 +08:00
Junyu Lai
85e24e85b2 [ST02] Add methods for synthesizing DNS packets
This re-submit aosp/1387135 but define TYPE_CNAME locally to
prevent from using non-finalize API.

Bug: 139774492
Test: atest NetworkStaticLibTests:com.android.net.moduletests.util.DnsPacketUtilsTest

Change-Id: Ib2e98292be994ca09845c6857b8884f9bcdaba80
2022-09-16 15:40:01 +08:00
Maciej Żenczykowski
1bff3fb28f NetlinkSocketTest.java - replace U32 ifindex with S32
These are allocated in order by the kernel, if we go
over 2 billion, we've got other problems... besides
U32 to S32 conversion will work just fine anyway.

(apparently this field is never accessed, as the test only looks at family)

Bug: 245472520
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I879c1637a87587b7bc1c13013ea9c5e655c141eb
2022-09-16 06:37:44 +00:00
Motomu Utsumi
1eb3792251 Add BpfDump#dumpMapStatus
Test: atest NetworkStaticLibTests
Change-Id: I77d397b16380a397573cc528fe7f15f381cda21f
2022-09-12 19:08:31 +09:00
Motomu Utsumi
9f732331a4 Merge "Add idiag_sock_id to InetDiagMessage class" 2022-09-10 02:02:11 +00:00
Anton Hansson
2464a31bf8 Merge "Revert "[ST02] Add methods for synthesizing DNS packets"" 2022-09-09 07:58:06 +00:00
Remi NGUYEN VAN
f53c488b93 Revert "[ST02] Add methods for synthesizing DNS packets"
Revert "[ST02.1] Add TYPE_CNAME constant to DnsResolver"

Revert submission 1387135-st02

Reason for revert: Usage of TYPE_CNAME in a library shared among
modules does not interact well with current module release process

Reverted Changes:
Ib5616c65c:[ST02.2] Use the getters of DnsHeader
I5e58f99b0:[ST02.1] Add TYPE_CNAME constant to DnsResolver
I0c1547cbc:[ST02] Add methods for synthesizing DNS packets

Change-Id: I9f8de47c9ba9fb4db7cf3695966f222f68a9a290
2022-09-08 11:01:05 +00:00
Junyu Lai
5e53d5390c Merge "[ST02] Add methods for synthesizing DNS packets" 2022-09-07 02:25:41 +00:00
Chalard Jean
e301436409 Introduce getResIntegerConfig
This is a symmetric to getResBooleanConfig for integers.

Test: new test in this patch
Change-Id: I36cb910acb59c3211ba2c77dd3784fefa93545d9
2022-09-06 11:23:25 +09:00
Motomu Utsumi
ea0fcc94ec Add idiag_sock_id to InetDiagMessage class
Bug: 217624062
Test: atest NetworkStaticLibTests
Change-Id: I9dc5b1d5b2d3da9ab21ce92b3f88d3f9d4d842f1
2022-09-05 21:59:25 +09:00
junyulai
96c4750d59 [ST02] Add methods for synthesizing DNS packets
Bug: 139774492
Test: atest NetworkStaticLibTests:com.android.net.moduletests.util.DnsPacketUtilsTest
Change-Id: I0c1547cbc1e7295e9a3dcb0f553065356b05bd7c
2022-09-05 10:16:24 +08:00
Jean Chalard
df8292c805 Merge "Add CollectionUtils.contains with predicate" 2022-09-03 03:27:03 +00:00
Chalard Jean
debdc78518 Add CollectionUtils.contains with predicate
Test: included in this patch
Change-Id: Id10c8878a8e7fe59fa2d7858212e4c01d4de1ca4
2022-08-31 15:55:20 +09:00
Motomu Utsumi
3becbd22dc Add BpfDump#dumpMap
Bug: 217624062
Test: atest NetworkStaticLibTests
Change-Id: I7b0a949e667da4120cc20d8587019bfb0f922584
2022-08-25 18:34:22 +09:00
Motomu Utsumi
fdfaa30146 Merge "Support StructInetDiagSockId parse" 2022-08-24 11:45:53 +00:00
Jean Chalard
8f31efb89c Merge "Add findFirst and findLast to CollectionsUtils" 2022-08-24 09:51:36 +00:00
Motomu Utsumi
56fa997164 Merge "Add test for StructInetDiagSockId" 2022-08-24 09:39:04 +00:00
Motomu Utsumi
dfe4251427 Merge "Add fromBase64EncodedString to BpfDump" 2022-08-24 03:16:53 +00:00
Treehugger Robot
eecde2bc87 Merge "Add getter to PerUidCounter" 2022-08-23 18:25:03 +00:00
Motomu Utsumi
556667ef02 Support StructInetDiagSockId parse
Bug: 217624062
Test: atest NetworkStaticLibTests
Change-Id: If42436459874d4c61037a98db18c43b40eb81066
2022-08-23 12:42:12 +09:00
Motomu Utsumi
fbc3280c79 Add test for StructInetDiagSockId
Upcoming CL will modify StructInetDiagSockId.
So, as a preparation, this CL adds test for existing behavior of
StructInetDiagSockId.

Bug: 217624062
Test: atest NetworkStaticLibTests
Change-Id: I6ef475bec050ba2689a8df6182be36a6fccd9bfb
2022-08-23 11:56:11 +09:00
Cole Faust
0d8bd9005d Add CollectionUtils.indexOfSubArray()
This is useful as an array version of Collections.indexOfSubList().

Bug: 242630963
Test: atest NetworkStaticLibTests
Change-Id: I36724791ceece1348826a51cb2a975e169dfecc6
2022-08-22 09:17:29 +09:00
Motomu Utsumi
4dcf00e78c Add fromBase64EncodedString to BpfDump
EthernetTetheringTest has parseMapKeyValue that decodes the string
encoded by BpfDump#toBase64EncodedString
Upcoming CL also wants to decode the encoded string.
So this CL renames parseMapKeyValue to fromBase64EncodedString and moves
to BpfDump with refactoring

Bug: 217624062
Test: atest NetworkStaticLibTests
Change-Id: I6ec302aaaa3e8779119cf153567cb032828f5daf
2022-08-18 12:38:24 +09:00
Junyu Lai
c0a6d524eb Add getter to PerUidCounter
This is needed by ConnectivityServiceTest, refer to the
counter part CL in the module git.

This CL also fix guarded by annotation and remove the
increment/decrement method with count methods, which
is not very useful.

Test: TH
Bug: 235771502
Change-Id: Iaab681bf456e14afb4c6ddf700eb3308abead35f
2022-08-17 14:17:42 +08:00
Chalard Jean
cc5f01c610 Add findFirst and findLast to CollectionsUtils
Test: new tests in this patch
Change-Id: Ie13ee7f50832ffec1febe4f4596d0b26e4c4a2f6
2022-08-17 01:44:13 +00:00
Paul Hu
3b5af9962d Add more tests to cover SharedLog methods
Add tests for SharedLog methods that do not have test coverage.
- SharedLog#reverseDump(java.io.PrintWriter)
- SharedLog#e(java.lang.Exception)
- SharedLog#getTag()
- SharedLog#i(java.lang.String)
- SharedLog#logf(java.lang.String, java.lang.Object[])
- SharedLog$LocalLog#reverseDump(java.io.PrintWriter)

Bug: 236768003
Test: atest NetworkStaticLibTests
Change-Id: I465b8e2d528fe70cddc49257d14fecad948fc50f
2022-07-14 06:17:59 +00:00
Hungming Chen
b3e71a2959 Add BpfDump.toBase64EncodedString to dump raw map
Move base64 related bpf map function and constant from BpfCoordinator.
This is preparation for testing BPF map in ClatCoordinator.

Test: atest NetworkStaticLibTests
Change-Id: I3a23393abe5b108cdb8d621e99b74fd20847474e
2022-07-06 04:34:34 +00:00
Xiao Ma
39c7bd7571 DeviceInfoUtils: add isKernelVersionAtLeast method.
Add a method to check if the current kernel version is at least from a
given version.

Bug: 236783925
Test: atest com.android.testutils.DeviceInfoUtilsTest --iterations
Change-Id: If0509b8ccad895c31d9447fee06789540002f666
2022-06-22 20:10:13 +09:00
Remi NGUYEN VAN
a79814aade Fix handling of Throwable in tryTest/catch
Throwable could be used as a type argument to catch(), but it would
possibly never be caught, because the method only catches Exception.

Notably, junit assertions fail with AssertionError, which is not a
subclass of Exception. Due to that, tests or utilities like
DeviceConfigRule that have failing assertions in catch() would not
run the subsequent cleanup steps.

Bug: 210377950
Test: atest CleanupTest
Change-Id: I54e2922cb466f077ba4d219f8c3c6f885316296c
2022-06-21 12:52:10 +09:00
Treehugger Robot
46cfe8b811 Merge "Ipv6UtilsTest: testBuildEchoReplyPacket" 2022-06-02 19:48:21 +00:00
Hungming Chen
39e1e8844c Ipv6UtilsTest: testBuildEchoReplyPacket
Bug: 183166581
Test: atest NetworkStaticLibTests
Change-Id: I2cd3a4142f3457cdf99547500ab2b93f8f96c314
2022-06-01 06:24:16 +00:00
Treehugger Robot
81c9d79102 Merge "DeviceInfoUtils: add class and helper for three-part version number" 2022-05-27 19:03:58 +00:00
Hungming Chen
085b7f442a DeviceInfoUtils: add class and helper for three-part version number
Add a class Version and string helper for handling a three-part
kernel version number.

Test: atest com.android.testutils.DeviceInfoUtilsTest
Bug: 232332847
Change-Id: I0f229e935bd8332ef2ef93fc910a576df9c054ae
2022-05-27 22:12:40 +08:00
Hungming Chen
690d1e15f5 PacketBuilder: correct IPv6 header payload length
Ipv6 payload length doesn't include header length.

rfc8200 section 3
https://tools.ietf.org/html/rfc8200
Payload Length      16-bit unsigned integer. Length of the IPv6
                    payload, i.e., the rest of the packet
                    following this IPv6 header, in octets.

Bug: 215655463
Test: atest NetworkStaticLibTests
Change-Id: Ifdc871125b0fe2eb3a8909b8b0723a62dbe44bcf
2022-05-27 10:48:52 +00:00
Treehugger Robot
ec25765f96 Merge changes I62771a8f,I5edf0ffb
* changes:
  PacketBuilderTest: add IPv6 TCP test
  PacketBuilder: add IPv6 support
2022-05-27 09:59:17 +00:00
Lorenzo Colitti
b02211a312 When parsing a netlink message, always advance to the end.
NetlinkEvent#parse relies on message-specific classes to parse
the payload of the message. If these classes do not consume the
entire message, parse does not advance to the end of the
message. This means that any code that loops over a ByteBuffer
parsing messages one at a time (e.g., NetlinkMonitor) will think
that there is still a message left to parse, and will attempt
to parse the remainder of the message as a new netlink message.
This is obviously incorrect for any buffer that contains more
than one netlink message.

Bug: 163492391
Test: existing unit tests
Change-Id: Ifdb9748068857f75ca00c58f0c40f19809aae5c9
2022-05-26 17:37:04 +09:00
Xiao Ma
6b6fc1b38d Add test to verify parsing multiple netlink messages in one buffer.
Currently the netlink parsing code doesn't advance to the end of message
if it doesn't consume the entire message, that results in the remaining
attributes will be considered as a new netlink message, parsing the
attributes will fail and return null. Have a testcase to verify this case.

Bug: 163492391
Test: atest NetworkStaticLibsTests
Change-Id: I2719cd917f9932d5e77002e615845076784139a2
2022-05-26 15:57:06 +09:00
Hungming Chen
3288afaede PacketBuilderTest: add IPv6 TCP test
Bug: 215655463
Test: atest NetworkStaticLibTests
Change-Id: I62771a8f2549c7785919504f4816a28f30551953
2022-05-17 22:35:11 +08:00
Hungming Chen
8ffa79ce34 PacketBuilder: add IPv6 support
Support IPv6 packet builder and verify with UDP packet unit test.

Bug: 215655463
Test: atest NetworkStaticLibTests

Change-Id: I5edf0ffbc9b37ecf0e0a6da0dc7d04716fc4c38c
2022-05-17 22:35:01 +08:00
Nucca Chen
f0c7ae630e Merge "Move DeviceInfoUtilsTest from NetworkStack to frameworks/lib/net" 2022-05-16 15:49:36 +00:00
Junyu Lai
22007784e2 Address comments at ag/18372083
This includes:
1. Fix synchronization error
2. Disallow 0 as maximum counter value
3. Fix comments

Test: atest NetworkStaticLibTests:com.android.net.moduletests.util.PerUidCounterTest
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.net.module.util.PerUidCounterTest
Bug: 229103088
Change-Id: I54c6017ffc62341d1a5da6591e5a045d687601d4
2022-05-16 10:57:46 +08:00
Junyu Lai
7c29887e0f Add PerUidCounter
The class keeps track of the counters under different uid,
fire exception if the counter exceeded the specified maximum
value.

This is reimplemented and generalized based on the one
inside ConnectivityService.

Test: atest NetworkStaticLibTests:com.android.net.moduletests.util.PerUidCounterTest
Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.net.module.util.PerUidCounterTest
Bug: 229103088
Change-Id: I7dfb16342e3ca4eab45bb40f2e1355981e04b44b
2022-05-12 16:09:31 +08:00
Hungming Chen
c9345142db Move DeviceInfoUtilsTest from NetworkStack to frameworks/lib/net
Test: atest com.android.testutils.DeviceInfoUtilsTest
Change-Id: Ib45dea951980eae0c1576d37842477192539a740
2022-05-09 21:20:36 +08:00
Taras Antoshchuk
630388df2c Check RouteInfo type in NetUtils#selectBestRoute
Change #selectBestRoute to account for non-unicast routes.
Method is used to detect if the address is reachable and via which
gateway. From that point of view, address being best matched by
a non-unicast route is equivalent to the address not being matched by
any route at all.

Method's implementation is adjusted to reflect the above logic. This
allows to avoid changing method's usages.

Bug: 186082280
Test: atest NetworkStaticLibTests:NetUtilsTest
Change-Id: I03f19d611fd8c7019cf13062bbeb1662d41402f4
2022-03-28 15:59:37 +02:00
Patrick Rohr
6230a517f3 Move InterfaceParamsTest to frameworks/libs/net
Test: atest NetworkStaticLibTests
Bug: 222448728
Change-Id: I9fc547203c592ad2ade506df68511468db6a5686
2022-03-04 17:43:57 +01:00
Aaron Huang
9f1fcb61d3 Add a method to convert public NetworkStats to internal NetworkStats
Bug: 210073043
Test: NetworkStaticLibTests
Change-Id: I769e023729b5a2743e60c211e9c4aeeff1f9f172
2022-01-17 23:09:07 +08:00
Chalard Jean
11ded06173 Fix int overflow in shift
Thankfully this is not actually a security vulnerability, because
the sign bit just gets set, and the conversion to long performs
sign extension. Still, it would break when adding one with 32.

To avoid repeats of this same mistake, convert the creation of
masks to using a function in a way that makes it impossible.

Test: new test for this in NetworkCapabilitiesUtilsTest
Change-Id: Iadbbca6b09b02d98e45a43984f7749e1a795ce02
2022-01-12 11:36:54 +09:00