Skip to content

Conversation

@carloslack
Copy link
Collaborator

Added a way of retrieving the vlan ID from skb
Tried to make it support non-linear skb and it is idiomatic for kernel 6.x ATM

However I wasn't able to fully test in a vlan network (working on that) but I think it is safe to PR this and get some reviews in the meantime.

@carloslack carloslack requested review from jperon and lneto January 29, 2026 09:54
Copy link
Contributor

@lneto lneto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still in doubt if we should use mark instead, associating a luanetfilter object to a specific VLAN ID.. another approach would be to have more SKB related methods on luadata or even evolve to inheritance, having a luaskb binding.. (@sneaky-potato I think that's a good reflection for you ;-).

That said, I would try to run some tests on this and comparing this approach and the one I mentioned using marks. I'm making some inline comments anyway, so it will help at least as a exercise for integration on our code base =).

goto out;

if (skb_mac_header_was_set(skb))
bool mac_header_was_set = skb_mac_header_was_set(skb);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we try to not have very long names..

Suggested change
bool mac_header_was_set = skb_mac_header_was_set(skb);
bool has_mac_header = skb_mac_header_was_set(skb);

couldn't figure anything better =)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the struggle :D
again, won't be needed (see below)

lua_pushnil(L); /* dev may be NULL if hook is LOCAL_OUT */

if (lua_pcall(L, 2, 2, 0) != LUA_OK) {
/* work out vlan TAG id, if present */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move the block below to an aux.. e.g., luanetfilter_pushvlanid

Copy link
Collaborator Author

@carloslack carloslack Jan 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I ignore if vlan is not present, like you suggested below, then the change is very small, probably won't need a helper

/* work out vlan TAG id, if present */
if (skb_vlan_tag_present(skb)) {
lua_pushinteger(L, skb_vlan_tag_get_id(skb));
} else if (mac_header_was_set && (skb->protocol == htons(ETH_P_8021Q) || skb->protocol == htons(ETH_P_8021AD))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we use \n after }, on if-then-else

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, if tag is not present, wouldn't be safe to give up? why should we extract it by ourselves? if needed, we can do this logic directly in lua, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes it more simple, I think it should be possible to retrieve from lua, similar to what we had in lldp example, for mac address.
I will push a change

if (veh)
lua_pushinteger(L, ntohs(veh->h_vlan_TCI) & VLAN_VID_MASK);
else
lua_pushnil(L);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need to pass nil as the third arg.. we can pass none.. it's both more luaish and clearer, I think.. for this, we might use a narg var and increment it in the cases we push it..

@lneto lneto requested a review from sheharyaar January 29, 2026 11:34
if (skb_vlan_tag_present(skb)) {
lua_pushinteger(L, skb_vlan_tag_get_id(skb));
narg++;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use the same approach for dev, for consistency ;-)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean, dropping narg and pushing nil if vlan not available?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant on if (de) do narg++ as well and suppress pushnil otherwise

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the same pattern ;-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could even have an inline for that..

Copy link
Collaborator Author

@carloslack carloslack Jan 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if we also make dev an optional arg, I think we'll have to push something so don't mess with expected arguments, on lua side?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right, we can have VLAN tag present, but not dev, right? If so, I agree, it might be confusing. I'd leave at this indeed. However, I think we should plan to implement a luaskb binding, so we can move most of this logic to there.. I put some thoughts on this, we can just have a method there to create a luadata, something like skb:todata(). I think it should be straight forward to implement and a good way to get more familiarized with lunatik modules.. =)

@lneto
Copy link
Contributor

lneto commented Jan 29, 2026

@sheharyaar it would be good to have your review before merging it..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants