snabb icon indicating copy to clipboard operation
snabb copied to clipboard

Fix LPM4 search error on non-existent entry

Open benagricola opened this issue 7 years ago • 9 comments

When attempting to :search_bytes() for an entry which doesn't exist, an error is generated:

(1) Lua metamethod '__index' at file 'core/main.lua:168'
	Local variables:
	 reason = string: "lib/lpm/lpm4.lua:44: attempt to index a nil value"
	 (*temporary) = C function: print
(2) Lua method 'search_bytes' at file 'lib/lpm/lpm4.lua:44'

This is because LPM4:search attempts to retrieve key from the returned (nil) value from :search_entry()

This fix checks that entry is not null before attempting to return the key.

benagricola avatar Sep 08 '17 16:09 benagricola

The build failure appears to be just that the LPM tests need CPU affinity, or they error out. I made a patch some weeks ago to fix this but due to Snabb's needlessly complicated merge policies, now we have to live with every PR to master failing for the next month :(

/cc @lukego; #1232 fixes this error

wingo avatar Sep 21 '17 08:09 wingo

Hi @benagricola,

Would you mind adding a test for this ?

Pete

petebristow avatar Sep 25 '17 15:09 petebristow

@petebristow Added a test for nonexistent entries returning nil, and also a nonexact prefix test.

Does this suffice?

benagricola avatar Sep 26 '17 11:09 benagricola

I'll merge this on the next sweep through PRs unless @petebristow has objections.

lukego avatar Nov 17 '17 11:11 lukego

Looks good to me.

petebristow avatar Nov 17 '17 19:11 petebristow

Having thought about this some more over in https://github.com/snabbco/snabb/issues/1238 and looked at my internal version. The reason the search function doesn't react well to a missing entry is because parts of the code base assume there will always be a default route. It's not documented, nor are there assertions in the code. Given that it may be a bad idea to merge this.

petebristow avatar Nov 17 '17 20:11 petebristow

@petebristow so to confirm, the correct way to use the LPM library is to always add a default route entry. If there's no actual default route, storing a 'NOT FOUND' value of some sort is required?

benagricola avatar Nov 20 '17 12:11 benagricola

Yes as it stands. I'm thinking it would be better if a) 0 is defined as the 'Not Found' entry b) If you don't install an explicit 0.0.0.0/0 then build adds one implicitly c) This is all documented in the README rather than a surprise feature.

What do you think ?

petebristow avatar Nov 20 '17 15:11 petebristow

Yep that sounds good. This is only a problem if you don't know that LPM requires a default / not found so implicitly adding one makes sense. I suppose you could still hit this issue if you deleted the implicitly added not found but as long as it's documented i think that makes sense.

benagricola avatar Nov 20 '17 15:11 benagricola