Commit be09f5bc7c0c3f0d0bc7b88d23dae883bfa4e014
Committed by
Joe Hershberger
1 parent
6880efdf5a
Exists in
smarc_8mq_lf_v2020.04
and in
12 other branches
net: fix env flags for eth10addr and above
With CONFIG_REGEX enabled, ETHADDR_WILDCARD is set up for up to 10 interfaces (0..9) as the number can only have one digit. On boards with more than 10 interfaces, this leads to the protection and format checks being absent for eth10addr and above. Fix this by changing ETHADDR_WILDCARD from "\\d?" to "\\d*" to allow more than one digit. Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Showing 1 changed file with 1 additions and 1 deletions Inline Diff
include/env_flags.h
1 | /* SPDX-License-Identifier: GPL-2.0+ */ | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
2 | /* | 2 | /* |
3 | * (C) Copyright 2012 | 3 | * (C) Copyright 2012 |
4 | * Joe Hershberger, National Instruments, joe.hershberger@ni.com | 4 | * Joe Hershberger, National Instruments, joe.hershberger@ni.com |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #ifndef __ENV_FLAGS_H__ | 7 | #ifndef __ENV_FLAGS_H__ |
8 | #define __ENV_FLAGS_H__ | 8 | #define __ENV_FLAGS_H__ |
9 | 9 | ||
10 | enum env_flags_vartype { | 10 | enum env_flags_vartype { |
11 | env_flags_vartype_string, | 11 | env_flags_vartype_string, |
12 | env_flags_vartype_decimal, | 12 | env_flags_vartype_decimal, |
13 | env_flags_vartype_hex, | 13 | env_flags_vartype_hex, |
14 | env_flags_vartype_bool, | 14 | env_flags_vartype_bool, |
15 | #ifdef CONFIG_CMD_NET | 15 | #ifdef CONFIG_CMD_NET |
16 | env_flags_vartype_ipaddr, | 16 | env_flags_vartype_ipaddr, |
17 | env_flags_vartype_macaddr, | 17 | env_flags_vartype_macaddr, |
18 | #endif | 18 | #endif |
19 | env_flags_vartype_end | 19 | env_flags_vartype_end |
20 | }; | 20 | }; |
21 | 21 | ||
22 | enum env_flags_varaccess { | 22 | enum env_flags_varaccess { |
23 | env_flags_varaccess_any, | 23 | env_flags_varaccess_any, |
24 | env_flags_varaccess_readonly, | 24 | env_flags_varaccess_readonly, |
25 | env_flags_varaccess_writeonce, | 25 | env_flags_varaccess_writeonce, |
26 | env_flags_varaccess_changedefault, | 26 | env_flags_varaccess_changedefault, |
27 | env_flags_varaccess_end | 27 | env_flags_varaccess_end |
28 | }; | 28 | }; |
29 | 29 | ||
30 | #define ENV_FLAGS_VAR ".flags" | 30 | #define ENV_FLAGS_VAR ".flags" |
31 | #define ENV_FLAGS_ATTR_MAX_LEN 2 | 31 | #define ENV_FLAGS_ATTR_MAX_LEN 2 |
32 | #define ENV_FLAGS_VARTYPE_LOC 0 | 32 | #define ENV_FLAGS_VARTYPE_LOC 0 |
33 | #define ENV_FLAGS_VARACCESS_LOC 1 | 33 | #define ENV_FLAGS_VARACCESS_LOC 1 |
34 | 34 | ||
35 | #ifndef CONFIG_ENV_FLAGS_LIST_STATIC | 35 | #ifndef CONFIG_ENV_FLAGS_LIST_STATIC |
36 | #define CONFIG_ENV_FLAGS_LIST_STATIC "" | 36 | #define CONFIG_ENV_FLAGS_LIST_STATIC "" |
37 | #endif | 37 | #endif |
38 | 38 | ||
39 | #ifdef CONFIG_CMD_NET | 39 | #ifdef CONFIG_CMD_NET |
40 | #ifdef CONFIG_REGEX | 40 | #ifdef CONFIG_REGEX |
41 | #define ETHADDR_WILDCARD "\\d?" | 41 | #define ETHADDR_WILDCARD "\\d*" |
42 | #else | 42 | #else |
43 | #define ETHADDR_WILDCARD | 43 | #define ETHADDR_WILDCARD |
44 | #endif | 44 | #endif |
45 | #ifdef CONFIG_ENV_OVERWRITE | 45 | #ifdef CONFIG_ENV_OVERWRITE |
46 | #define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:ma," | 46 | #define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:ma," |
47 | #else | 47 | #else |
48 | #ifdef CONFIG_OVERWRITE_ETHADDR_ONCE | 48 | #ifdef CONFIG_OVERWRITE_ETHADDR_ONCE |
49 | #define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mc," | 49 | #define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mc," |
50 | #else | 50 | #else |
51 | #define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mo," | 51 | #define ETHADDR_FLAGS "eth" ETHADDR_WILDCARD "addr:mo," |
52 | #endif | 52 | #endif |
53 | #endif | 53 | #endif |
54 | #define NET_FLAGS \ | 54 | #define NET_FLAGS \ |
55 | "ipaddr:i," \ | 55 | "ipaddr:i," \ |
56 | "gatewayip:i," \ | 56 | "gatewayip:i," \ |
57 | "netmask:i," \ | 57 | "netmask:i," \ |
58 | "serverip:i," \ | 58 | "serverip:i," \ |
59 | "nvlan:d," \ | 59 | "nvlan:d," \ |
60 | "vlan:d," \ | 60 | "vlan:d," \ |
61 | "dnsip:i," | 61 | "dnsip:i," |
62 | #else | 62 | #else |
63 | #define ETHADDR_FLAGS | 63 | #define ETHADDR_FLAGS |
64 | #define NET_FLAGS | 64 | #define NET_FLAGS |
65 | #endif | 65 | #endif |
66 | 66 | ||
67 | #ifndef CONFIG_ENV_OVERWRITE | 67 | #ifndef CONFIG_ENV_OVERWRITE |
68 | #define SERIAL_FLAGS "serial#:so," | 68 | #define SERIAL_FLAGS "serial#:so," |
69 | #else | 69 | #else |
70 | #define SERIAL_FLAGS "" | 70 | #define SERIAL_FLAGS "" |
71 | #endif | 71 | #endif |
72 | 72 | ||
73 | #define ENV_FLAGS_LIST_STATIC \ | 73 | #define ENV_FLAGS_LIST_STATIC \ |
74 | ETHADDR_FLAGS \ | 74 | ETHADDR_FLAGS \ |
75 | NET_FLAGS \ | 75 | NET_FLAGS \ |
76 | SERIAL_FLAGS \ | 76 | SERIAL_FLAGS \ |
77 | CONFIG_ENV_FLAGS_LIST_STATIC | 77 | CONFIG_ENV_FLAGS_LIST_STATIC |
78 | 78 | ||
79 | #ifdef CONFIG_CMD_ENV_FLAGS | 79 | #ifdef CONFIG_CMD_ENV_FLAGS |
80 | /* | 80 | /* |
81 | * Print the whole list of available type flags. | 81 | * Print the whole list of available type flags. |
82 | */ | 82 | */ |
83 | void env_flags_print_vartypes(void); | 83 | void env_flags_print_vartypes(void); |
84 | /* | 84 | /* |
85 | * Print the whole list of available access flags. | 85 | * Print the whole list of available access flags. |
86 | */ | 86 | */ |
87 | void env_flags_print_varaccess(void); | 87 | void env_flags_print_varaccess(void); |
88 | /* | 88 | /* |
89 | * Return the name of the type. | 89 | * Return the name of the type. |
90 | */ | 90 | */ |
91 | const char *env_flags_get_vartype_name(enum env_flags_vartype type); | 91 | const char *env_flags_get_vartype_name(enum env_flags_vartype type); |
92 | /* | 92 | /* |
93 | * Return the name of the access. | 93 | * Return the name of the access. |
94 | */ | 94 | */ |
95 | const char *env_flags_get_varaccess_name(enum env_flags_varaccess access); | 95 | const char *env_flags_get_varaccess_name(enum env_flags_varaccess access); |
96 | #endif | 96 | #endif |
97 | 97 | ||
98 | /* | 98 | /* |
99 | * Parse the flags string from a .flags attribute list into the vartype enum. | 99 | * Parse the flags string from a .flags attribute list into the vartype enum. |
100 | */ | 100 | */ |
101 | enum env_flags_vartype env_flags_parse_vartype(const char *flags); | 101 | enum env_flags_vartype env_flags_parse_vartype(const char *flags); |
102 | /* | 102 | /* |
103 | * Parse the flags string from a .flags attribute list into the varaccess enum. | 103 | * Parse the flags string from a .flags attribute list into the varaccess enum. |
104 | */ | 104 | */ |
105 | enum env_flags_varaccess env_flags_parse_varaccess(const char *flags); | 105 | enum env_flags_varaccess env_flags_parse_varaccess(const char *flags); |
106 | /* | 106 | /* |
107 | * Parse the binary flags from a hash table entry into the varaccess enum. | 107 | * Parse the binary flags from a hash table entry into the varaccess enum. |
108 | */ | 108 | */ |
109 | enum env_flags_varaccess env_flags_parse_varaccess_from_binflags(int binflags); | 109 | enum env_flags_varaccess env_flags_parse_varaccess_from_binflags(int binflags); |
110 | 110 | ||
111 | #ifdef CONFIG_CMD_NET | 111 | #ifdef CONFIG_CMD_NET |
112 | /* | 112 | /* |
113 | * Check if a string has the format of an Ethernet MAC address | 113 | * Check if a string has the format of an Ethernet MAC address |
114 | */ | 114 | */ |
115 | int eth_validate_ethaddr_str(const char *addr); | 115 | int eth_validate_ethaddr_str(const char *addr); |
116 | #endif | 116 | #endif |
117 | 117 | ||
118 | #ifdef USE_HOSTCC | 118 | #ifdef USE_HOSTCC |
119 | /* | 119 | /* |
120 | * Look up the type of a variable directly from the .flags var. | 120 | * Look up the type of a variable directly from the .flags var. |
121 | */ | 121 | */ |
122 | enum env_flags_vartype env_flags_get_type(const char *name); | 122 | enum env_flags_vartype env_flags_get_type(const char *name); |
123 | /* | 123 | /* |
124 | * Look up the access of a variable directly from the .flags var. | 124 | * Look up the access of a variable directly from the .flags var. |
125 | */ | 125 | */ |
126 | enum env_flags_varaccess env_flags_get_access(const char *name); | 126 | enum env_flags_varaccess env_flags_get_access(const char *name); |
127 | /* | 127 | /* |
128 | * Validate the newval for its type to conform with the requirements defined by | 128 | * Validate the newval for its type to conform with the requirements defined by |
129 | * its flags (directly looked at the .flags var). | 129 | * its flags (directly looked at the .flags var). |
130 | */ | 130 | */ |
131 | int env_flags_validate_type(const char *name, const char *newval); | 131 | int env_flags_validate_type(const char *name, const char *newval); |
132 | /* | 132 | /* |
133 | * Validate the newval for its access to conform with the requirements defined | 133 | * Validate the newval for its access to conform with the requirements defined |
134 | * by its flags (directly looked at the .flags var). | 134 | * by its flags (directly looked at the .flags var). |
135 | */ | 135 | */ |
136 | int env_flags_validate_access(const char *name, int check_mask); | 136 | int env_flags_validate_access(const char *name, int check_mask); |
137 | /* | 137 | /* |
138 | * Validate that the proposed access to variable "name" is valid according to | 138 | * Validate that the proposed access to variable "name" is valid according to |
139 | * the defined flags for that variable, if any. | 139 | * the defined flags for that variable, if any. |
140 | */ | 140 | */ |
141 | int env_flags_validate_varaccess(const char *name, int check_mask); | 141 | int env_flags_validate_varaccess(const char *name, int check_mask); |
142 | /* | 142 | /* |
143 | * Validate the parameters passed to "env set" for type compliance | 143 | * Validate the parameters passed to "env set" for type compliance |
144 | */ | 144 | */ |
145 | int env_flags_validate_env_set_params(char *name, char *const val[], int count); | 145 | int env_flags_validate_env_set_params(char *name, char *const val[], int count); |
146 | 146 | ||
147 | #else /* !USE_HOSTCC */ | 147 | #else /* !USE_HOSTCC */ |
148 | 148 | ||
149 | #include <search.h> | 149 | #include <search.h> |
150 | 150 | ||
151 | /* | 151 | /* |
152 | * When adding a variable to the environment, initialize the flags for that | 152 | * When adding a variable to the environment, initialize the flags for that |
153 | * variable. | 153 | * variable. |
154 | */ | 154 | */ |
155 | void env_flags_init(ENTRY *var_entry); | 155 | void env_flags_init(ENTRY *var_entry); |
156 | 156 | ||
157 | /* | 157 | /* |
158 | * Validate the newval for to conform with the requirements defined by its flags | 158 | * Validate the newval for to conform with the requirements defined by its flags |
159 | */ | 159 | */ |
160 | int env_flags_validate(const ENTRY *item, const char *newval, enum env_op op, | 160 | int env_flags_validate(const ENTRY *item, const char *newval, enum env_op op, |
161 | int flag); | 161 | int flag); |
162 | 162 | ||
163 | #endif /* USE_HOSTCC */ | 163 | #endif /* USE_HOSTCC */ |
164 | 164 | ||
165 | /* | 165 | /* |
166 | * These are the binary flags used in the environment entry->flags variable to | 166 | * These are the binary flags used in the environment entry->flags variable to |
167 | * decribe properties of veriables in the table | 167 | * decribe properties of veriables in the table |
168 | */ | 168 | */ |
169 | #define ENV_FLAGS_VARTYPE_BIN_MASK 0x00000007 | 169 | #define ENV_FLAGS_VARTYPE_BIN_MASK 0x00000007 |
170 | /* The actual variable type values use the enum value (within the mask) */ | 170 | /* The actual variable type values use the enum value (within the mask) */ |
171 | #define ENV_FLAGS_VARACCESS_PREVENT_DELETE 0x00000008 | 171 | #define ENV_FLAGS_VARACCESS_PREVENT_DELETE 0x00000008 |
172 | #define ENV_FLAGS_VARACCESS_PREVENT_CREATE 0x00000010 | 172 | #define ENV_FLAGS_VARACCESS_PREVENT_CREATE 0x00000010 |
173 | #define ENV_FLAGS_VARACCESS_PREVENT_OVERWR 0x00000020 | 173 | #define ENV_FLAGS_VARACCESS_PREVENT_OVERWR 0x00000020 |
174 | #define ENV_FLAGS_VARACCESS_PREVENT_NONDEF_OVERWR 0x00000040 | 174 | #define ENV_FLAGS_VARACCESS_PREVENT_NONDEF_OVERWR 0x00000040 |
175 | #define ENV_FLAGS_VARACCESS_BIN_MASK 0x00000078 | 175 | #define ENV_FLAGS_VARACCESS_BIN_MASK 0x00000078 |
176 | 176 | ||
177 | #endif /* __ENV_FLAGS_H__ */ | 177 | #endif /* __ENV_FLAGS_H__ */ |
178 | 178 |