Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lua is loaded into an empty namespace, preventing key Lua functions #16900

Closed
2 tasks done
Cerebus opened this issue Sep 23, 2024 · 2 comments · Fixed by #16907
Closed
2 tasks done

Lua is loaded into an empty namespace, preventing key Lua functions #16900

Cerebus opened this issue Sep 23, 2024 · 2 comments · Fixed by #16907
Assignees
Labels

Comments

@Cerebus
Copy link

Cerebus commented Sep 23, 2024

Description

The Lua scripting environment loads the user script into an empty namespace, preventing necessary Lua functions like pairs() and ipairs form working. This makes it impossible to iterate over Lua tables, which is pretty important capability.

Version

Hello, this is FRRouting (version 10.2-dev_git20240920)

How to reproduce

Try the following:

function on_rib_process_dplane_results(ctx)
    if ctx.rinfo.zd_ng then
        for k, v in pairs(ctx.rinfo.zd_ng) do
            log.info("entry=" .. k .. " ifindex=" .. v.ifindex)
        end
    end
    return {}
end

Expected behavior

I should get a log entry for each entry in the nexthop group.

Actual behavior

The script will throw an exception:

Lua hook call 'on_rib_process_dplane_results' : runtime error: /etc/frr/scripts/logger.lua:3: attempt to call a nil value (global 'pairs')

Additional context

This kind of error is typical in Lua modules that use the deprecated module() function to create modules. This function creates a new namespace (or table, b/c it's Lua everything is a table) for the module definitions, and the global namespace is no longer accessible. Welcome to Lua. :)

See here for more detail:

http://lua-users.org/wiki/ModulesTutorial

See also #16847.

Checklist

  • I have searched the open issues for this bug.
  • I have not included sensitive information in this report.
@Cerebus Cerebus added the triage Needs further investigation label Sep 23, 2024
@ton31337 ton31337 removed the triage Needs further investigation label Sep 24, 2024
@ton31337 ton31337 self-assigned this Sep 24, 2024
@ton31337 ton31337 added the lua label Sep 24, 2024
@ton31337
Copy link
Member

Should be fixed by #16907.

@Cerebus
Copy link
Author

Cerebus commented Oct 7, 2024

Finally back to this task. Confirmed on current HEAD. Thanks much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants