Igalia / pflua

Packet filtering in Lua
Other
313 stars 39 forks source link

Add required libraries when printing out source code #127

Closed dpino closed 9 years ago

dpino commented 9 years ago

I noticed that when passing { source = true } to compile_pflua doesn't print out the source code of the required libraries (the ones that are passed in env).

For instance, if I print out a function with pflua-compile:

tools $ ./pflua-compile "tcp port 80" > func.lua

And later try to use that function in pflua-match:

tools $ ./pflua-match v4.pcap func.lua

I will get an error because function cast (all the functions that are passed in the environment) doesn't exist.

luajit: func.lua:16: attempt to call global 'cast' (a nil value)
stack traceback:
    func.lua:16: in function 'pred'
    ./pflua-match:26: in function 'filter'
    ./pflua-match:60: in function 'main'
    ./pflua-match:84: in main chunk
    [C]: at 0x004061b0

Is this the intended behaviour? Should we let the user to append manually the functions used? In case of fixing it, it'd be necessary to include the definition of functions runtime_u32, runtime_add, etc for the bpf pipeline.

wingo commented 9 years ago

Humm, I don't know! Perhaps we could simply define a "standard prologue" ?

  1. Add entries from pf.backend.env to pf.bpf.env and use them, just for consistency
  2. Declare a "standard prologue" for all pflua functions, with additional definitions for BPF (runtime_u32 et al)
  3. Document this somewhere, perhaps defining a wrap_source(source) function that can turn source into a function, having done the setfenv and all, for people wanting to test

wdyt?

kbara commented 9 years ago

Andy Wingo wrote:

Perhaps we could simply define a "standard prologue" ? ... Plausible, and it'd increase consistency over the rest of our code, and get rid of other places where that's been an annoyance.

kbara commented 9 years ago

Does #134 sufficiently address this - can it be closed now?