Commit c1843fa
authored
Issue sonic-net#22759: Prevent CLI from adding invalid routed interfaces (sonic-net#3901)
What I did
Currently, config interface ip add will accept EthernetX interfaces which do not have an underlying port or portchannel associated with them. This violates the yang model, so if these entries are added to ConfigDB, 'config replace' and 'config reload' don't work properly. To make matters worse, the implementation of config interface ip remove does not detect these invalid entries, so once they are added they cannot be removed through the CLI. I modified the command to reject invalid cases.
Fixes: sonic-net#22759
How I did it
Add a check for this case into the config interface ip add CLI command to avoid invalid cases of this form by checking to ensure that the interface which is passed is associated with a valid port or port channel if it is an Ethernet or PortChannel interface. There is already an existing check for vlan interfaces.
How to verify it
Modify existing test cases to handle expected behavior, verify that they all pass.
Previous command output (if the output of a command-line utility has changed)
admin@gold113-dut:~$ sudo config interface ip add EthernetNR 1.2.3.4
admin@gold113-dut:~$ sudo config interface ip add EthernetJustMadeUp 1.2.3.4
admin@gold113-dut:~$ sudo config interface ip add Ethernet99999999 1.2.3.4
admin@gold113-dut:~$ sudo config interface ip add Ethernet-totally-not-real 1.2.3.4
admin@gold113-dut:~$ sudo config interface ip remove EthernetNR 1.2.3.4
Cannot find device "EthernetNR"
admin@gold113-dut:~$ sudo config replace -d /etc/sonic/config_db.json
** DRY RUN EXECUTION **
Config Replacer: Config replacement starting.
Config Replacer: Target config length: 50412.
Config Replacer: Getting current config db.
Config Replacer: Generating patch between target config and current config db.
Config Replacer: Applying patch using 'Patch Applier'.
Patch Applier: localhost: Patch application starting.
Patch Applier: localhost: Patch: [{"op": "remove", "path": "/INTERFACE/EthernetJustMadeUp"}, {"op": "remove", "path": "/INTERFACE/Ethernet-totally-not-real"}, {"op": "remove", "path": "/INTERFACE/EthernetNR"}, {"op": "remove", "path": "/INTERFACE/Ethernet99999999"}, {"op": "remove", "path": "/INTERFACE/EthernetJustMadeUp|1.2.3.4~132"}, {"op": "remove", "path": "/INTERFACE/Ethernet99999999|1.2.3.4~132"}, {"op": "remove", "path": "/INTERFACE/Ethernet-totally-not-real|1.2.3.4~132"}, {"op": "remove", "path": "/INTERFACE/EthernetNR|1.2.3.4~132"}]
Patch Applier: localhost getting current config db.
Patch Applier: localhost: simulating the target full config after applying the patch.
Patch Applier: localhost: validating all JsonPatch operations are permitted on the specified fields
Patch Applier: localhost: validating target config does not have empty tables,
since they do not show up in ConfigDb.
Patch Applier: localhost: sorting patch updates.
Failed to replace config
Usage: config replace [OPTIONS] TARGET_FILE_PATH
Try "config replace -h" for help.
Error: Data Loading Failed
Leafref "/sonic-port:sonic-port/sonic-port:PORT/sonic-port:PORT_LIST/sonic-port:name" of value "EthernetNR" points to a non-existing leaf.
New command output (if the output of a command-line utility has changed)
admin@gold113-dut:~$ sudo config interface ip add EthernetNR.10 1.2.3.4
Usage: config interface ip add [OPTIONS] <interface_name> <ip_addr> <default
gateway IP address>
Try "config interface ip add -h" for help.
Error: Interface EthernetNR.10 does not exist1 parent 7c5378e commit c1843fa
4 files changed
Lines changed: 371 additions & 210 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5222 | 5222 | | |
5223 | 5223 | | |
5224 | 5224 | | |
5225 | | - | |
5226 | | - | |
5227 | | - | |
5228 | | - | |
5229 | | - | |
5230 | | - | |
5231 | | - | |
5232 | | - | |
5233 | 5225 | | |
5234 | | - | |
5235 | | - | |
5236 | | - | |
5237 | | - | |
5238 | | - | |
5239 | | - | |
5240 | | - | |
5241 | | - | |
5242 | | - | |
5243 | | - | |
5244 | | - | |
5245 | | - | |
5246 | | - | |
5247 | | - | |
5248 | | - | |
5249 | | - | |
5250 | | - | |
5251 | | - | |
5252 | | - | |
5253 | | - | |
5254 | | - | |
5255 | | - | |
5256 | | - | |
5257 | | - | |
5258 | | - | |
5259 | | - | |
5260 | | - | |
5261 | | - | |
5262 | | - | |
5263 | | - | |
5264 | | - | |
5265 | | - | |
5266 | 5226 | | |
5267 | 5227 | | |
5268 | 5228 | | |
| |||
5293 | 5253 | | |
5294 | 5254 | | |
5295 | 5255 | | |
5296 | | - | |
| 5256 | + | |
| 5257 | + | |
| 5258 | + | |
| 5259 | + | |
| 5260 | + | |
| 5261 | + | |
| 5262 | + | |
| 5263 | + | |
| 5264 | + | |
| 5265 | + | |
| 5266 | + | |
| 5267 | + | |
| 5268 | + | |
| 5269 | + | |
| 5270 | + | |
| 5271 | + | |
| 5272 | + | |
| 5273 | + | |
| 5274 | + | |
| 5275 | + | |
| 5276 | + | |
| 5277 | + | |
| 5278 | + | |
| 5279 | + | |
| 5280 | + | |
| 5281 | + | |
| 5282 | + | |
| 5283 | + | |
| 5284 | + | |
| 5285 | + | |
| 5286 | + | |
| 5287 | + | |
| 5288 | + | |
| 5289 | + | |
| 5290 | + | |
| 5291 | + | |
| 5292 | + | |
| 5293 | + | |
| 5294 | + | |
| 5295 | + | |
| 5296 | + | |
| 5297 | + | |
| 5298 | + | |
| 5299 | + | |
| 5300 | + | |
| 5301 | + | |
| 5302 | + | |
| 5303 | + | |
| 5304 | + | |
| 5305 | + | |
| 5306 | + | |
| 5307 | + | |
| 5308 | + | |
| 5309 | + | |
| 5310 | + | |
| 5311 | + | |
| 5312 | + | |
| 5313 | + | |
| 5314 | + | |
5297 | 5315 | | |
5298 | 5316 | | |
5299 | 5317 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
84 | 116 | | |
85 | 117 | | |
86 | 118 | | |
| |||
105 | 137 | | |
106 | 138 | | |
107 | 139 | | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
108 | 158 | | |
109 | 159 | | |
110 | 160 | | |
| |||
137 | 187 | | |
138 | 188 | | |
139 | 189 | | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
140 | 210 | | |
141 | 211 | | |
142 | 212 | | |
| |||
212 | 282 | | |
213 | 283 | | |
214 | 284 | | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
215 | 359 | | |
216 | 360 | | |
217 | 361 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1490 | 1490 | | |
1491 | 1491 | | |
1492 | 1492 | | |
1493 | | - | |
1494 | 1493 | | |
1495 | 1494 | | |
1496 | 1495 | | |
| |||
0 commit comments