• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.server.util;
18 
19 import static android.net.shared.Inet4AddressUtils.intToInet4AddressHTH;
20 
21 import java.net.Inet4Address;
22 
23 /**
24  * Network constants used by the network stack.
25  */
26 public final class NetworkStackConstants {
27 
28     /**
29      * IPv4 constants.
30      *
31      * See also:
32      *     - https://tools.ietf.org/html/rfc791
33      */
34     public static final int IPV4_ADDR_BITS = 32;
35     public static final int IPV4_MIN_MTU = 68;
36     public static final int IPV4_MAX_MTU = 65_535;
37 
38     /**
39      * Ethernet constants.
40      *
41      * See also:
42      *     - https://tools.ietf.org/html/rfc894
43      *     - https://tools.ietf.org/html/rfc2464
44      *     - https://tools.ietf.org/html/rfc7042
45      *     - http://www.iana.org/assignments/ethernet-numbers/ethernet-numbers.xhtml
46      *     - http://www.iana.org/assignments/ieee-802-numbers/ieee-802-numbers.xhtml
47      */
48     public static final int ETHER_DST_ADDR_OFFSET = 0;
49     public static final int ETHER_SRC_ADDR_OFFSET = 6;
50     public static final int ETHER_ADDR_LEN = 6;
51     public static final int ETHER_TYPE_OFFSET = 12;
52     public static final int ETHER_TYPE_LENGTH = 2;
53     public static final int ETHER_TYPE_ARP  = 0x0806;
54     public static final int ETHER_TYPE_IPV4 = 0x0800;
55     public static final int ETHER_TYPE_IPV6 = 0x86dd;
56     public static final int ETHER_HEADER_LEN = 14;
57 
58     /**
59      * ARP constants.
60      *
61      * See also:
62      *     - https://tools.ietf.org/html/rfc826
63      *     - http://www.iana.org/assignments/arp-parameters/arp-parameters.xhtml
64      */
65     public static final int ARP_PAYLOAD_LEN = 28;  // For Ethernet+IPv4.
66     public static final int ARP_REQUEST = 1;
67     public static final int ARP_REPLY   = 2;
68     public static final int ARP_HWTYPE_RESERVED_LO = 0;
69     public static final int ARP_HWTYPE_ETHER       = 1;
70     public static final int ARP_HWTYPE_RESERVED_HI = 0xffff;
71 
72     /**
73      * IPv4 constants.
74      *
75      * See also:
76      *     - https://tools.ietf.org/html/rfc791
77      */
78     public static final int IPV4_HEADER_MIN_LEN = 20;
79     public static final int IPV4_IHL_MASK = 0xf;
80     public static final int IPV4_FLAGS_OFFSET = 6;
81     public static final int IPV4_FRAGMENT_MASK = 0x1fff;
82     public static final int IPV4_PROTOCOL_OFFSET = 9;
83     public static final int IPV4_SRC_ADDR_OFFSET = 12;
84     public static final int IPV4_DST_ADDR_OFFSET = 16;
85     public static final int IPV4_ADDR_LEN = 4;
86     public static final Inet4Address IPV4_ADDR_ALL = intToInet4AddressHTH(0xffffffff);
87     public static final Inet4Address IPV4_ADDR_ANY = intToInet4AddressHTH(0x0);
88 
89     /**
90      * IPv6 constants.
91      *
92      * See also:
93      *     - https://tools.ietf.org/html/rfc2460
94      */
95     public static final int IPV6_ADDR_LEN = 16;
96     public static final int IPV6_HEADER_LEN = 40;
97     public static final int IPV6_PROTOCOL_OFFSET = 6;
98     public static final int IPV6_SRC_ADDR_OFFSET = 8;
99     public static final int IPV6_DST_ADDR_OFFSET = 24;
100 
101     /**
102      * ICMPv6 constants.
103      *
104      * See also:
105      *     - https://tools.ietf.org/html/rfc4443
106      *     - https://tools.ietf.org/html/rfc4861
107      */
108     public static final int ICMPV6_HEADER_MIN_LEN = 4;
109     public static final int ICMPV6_ECHO_REPLY_TYPE = 129;
110     public static final int ICMPV6_ECHO_REQUEST_TYPE = 128;
111     public static final int ICMPV6_ROUTER_SOLICITATION    = 133;
112     public static final int ICMPV6_ROUTER_ADVERTISEMENT   = 134;
113     public static final int ICMPV6_NEIGHBOR_SOLICITATION  = 135;
114     public static final int ICMPV6_NEIGHBOR_ADVERTISEMENT = 136;
115     public static final int ICMPV6_ND_OPTION_MIN_LENGTH = 8;
116     public static final int ICMPV6_ND_OPTION_LENGTH_SCALING_FACTOR = 8;
117     public static final int ICMPV6_ND_OPTION_SLLA = 1;
118     public static final int ICMPV6_ND_OPTION_TLLA = 2;
119     public static final int ICMPV6_ND_OPTION_MTU  = 5;
120 
121     /**
122      * UDP constants.
123      *
124      * See also:
125      *     - https://tools.ietf.org/html/rfc768
126      */
127     public static final int UDP_HEADER_LEN = 8;
128 
129 
130     /**
131      * DHCP constants.
132      *
133      * See also:
134      *     - https://tools.ietf.org/html/rfc2131
135      */
136     public static final int INFINITE_LEASE = 0xffffffff;
137     public static final int DHCP4_CLIENT_PORT = 68;
138 
NetworkStackConstants()139     private NetworkStackConstants() {
140         throw new UnsupportedOperationException("This class is not to be instantiated");
141     }
142 }
143