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

proxy of <Swig Object of type 'config_strlist *' at 0x7fedc716a690> #79

Closed
SasanKSMC opened this issue Sep 18, 2019 · 14 comments
Closed
Assignees

Comments

@SasanKSMC
Copy link

The following warning has started to appear using pythonmod since 1.9.3:

script <unboundmodule.config_strlist; proxy of <Swig Object of type 'config_strlist *' at 0x7fedc716a690> >

@gthess
Copy link
Member

gthess commented Oct 10, 2019

I think this logging may come from the python script itself. Can you check?

@SasanKSMC
Copy link
Author

I'm confident that I have not enabled any extra logging compared to 1.9.2. It is the same script.

@gthess
Copy link
Member

gthess commented Oct 10, 2019

Is this the whole logged line? Also does it appear more than once?
By the way this seems like a (python) print of the object that holds the script's name. Not an actual warning/error.

@SasanKSMC
Copy link
Author

yes it is the whole line. It appears once the unbound is loading and doesn't show up again while unbound is running.

@gthess
Copy link
Member

gthess commented Oct 10, 2019

Could you share the init function(s) from the python script?

@SasanKSMC
Copy link
Author

def init(id, cfg):
    log_info("pythonmod: init called, module id is %d port: %d script: %s" % (id, cfg.port, cfg.python_script))
    return True

@gthess
Copy link
Member

gthess commented Oct 10, 2019

I suppose you also see the other part? pythonmod: init called, module id is ...

@gthess
Copy link
Member

gthess commented Oct 10, 2019

Could you also run:
unbound-control get_option "verbosity"
and
unbound-control get_option "python-script"
while unbound is running?

@SasanKSMC
Copy link
Author

SasanKSMC commented Oct 10, 2019

unbound -d -v -c /usr/local/etc/unbound/2.conf [1568579786] unbound[1870:0] notice: Start of unbound 1.9.3. [1568579786] unbound[1870:0] notice: init module 0: python [1568579786] unbound[1870:0] info: pythonmod: script loaded. [1568579786] unbound[1870:0] info: myScript: script <unboundmodule.config_strlist; proxy of <Swig Object of type 'config_strlist *' at 0x7f7dd14210> > [1568579786] unbound[1870:0] notice: init module 1: subnet [1568579786] unbound[1870:0] notice: init module 2: iterator [1568579787] unbound[1870:0] info: start of service (unbound 1.9.3).

@yds
Copy link

yds commented Mar 3, 2020

I'm having the same issue:

def init(id, cfg):
    log_info("pythonmod: init called, module id is %d port: %d script: %s" % (id, cfg.port, cfg.python_script))
    log_info("pythonmod: cfg.ifs: %s" % cfg.ifs)
    return True

logs this:

unbound[6104:0] info: pythonmod: init called, module id is 1 port: 53 script: <unboundmodule.config_strlist; proxy of <Swig Object of type 'config_strlist *' at 0x802002e40> >
unbound[6104:0] info: pythonmod: cfg.ifs: <Swig Object of type 'char **' at 0x802002de0>

prior to this issue cfg.python_script would return a str with the name of the configured python script. Now it seems like all of the config_file str type values return the Swig Object type instead of the value as per the config_file docs.

Here's a production script I've had working for years which now breaks on this line:

config = yaml.load(open(os.path.splitext(cfg.python_script)[0]+'.yml'), Loader=yaml.CSafeLoader)
% unbound-control get_option "python-script"
/usr/local/etc/unbound/views.py

@gthess
Copy link
Member

gthess commented Mar 4, 2020

This is a problem from 1.9.3 onwards when multiple python instances were introduced (#6).
The python_script is not a string anymore, instead it is a linked list of the available scirpts.
I will revisit the multi-python related behavior and also make this more easily accessible.

For now you could use python_script.str to access the filename given that you only use one python script.
If you use more, each script would need to know its order and traverse the linked list. python_script.next points to the next node (if any).

@yds
Copy link

yds commented Mar 5, 2020

Is there any documentation of this new pythonmod API? The config_file docs do not offer much of a clue on how to access the non-pythonic str type objects.

for example:

log_info("pythonmod: cfg.ifs: %s" % cfg.ifs)

outputs:

unbound[6104:0] info: pythonmod: cfg.ifs: <Swig Object of type 'char **' at 0x802002de0>

while config_file documents the cfg.ifs attribute is supposed to return:

Interface description strings (IP addresses).

I'm not sure if that's a list of strings or a sting of IP addresses (separated by?) -- either way Swig Object of type 'char **' does not offer much of a clue how to get information out of the config_file object.

If the API needs to change to accommodate running multiple python instances, would it be possible to keep the API more "Pythonic"? e.g. this str(python_script) NOT this python_script.str -- maybe make ``python_script` return a tuple of strings. It shouldn't be this convoluted to get at string values from within python is what I'm saying. ;-)

From my end user perspective it looks like #6 makes an undocumented way of using multiple python instances work while breaking the documented pythonmod API.

@gthess
Copy link
Member

gthess commented Mar 9, 2020

I am afraid there is no easy way now (without updating the Swig interface) to get the cfg.ifs values.
The same goes with the cfg.out_ifs.

As for the python_script.str way of getting the string, it is automatic type conversion from Swig; it just maps the C struct to Python. This should be fixed with a Swig interface update.

I'll work on that together with the other Python issues when I have some time, but not a top priority now.

@gthess gthess closed this as completed in 63a5280 Oct 16, 2023
gthess added a commit that referenced this issue Oct 16, 2023
  a list of strings in the Python 'config_file' class instead of the
  current Swig object proxy; fixes #79.
@gthess
Copy link
Member

gthess commented Oct 16, 2023

Notes on the latest commit:

  • the python script filename is now available with mod_env['script'] and the old location (cfg.python_script) is now deprecated (also printed in text when used). This will always print the filename of the current Python module (in a multi Python module configuration);
  • cfg.ifs and cfg.out_ifs are now lists of strings.

jedisct1 added a commit to jedisct1/unbound that referenced this issue Oct 24, 2023
* nlnet/master: (64 commits)
  Changelog entry for NLnetLabs#951. - Merge NLnetLabs#951: Cachedb no store. The cachedb-no-store: yes option is   used to stop cachedb from writing messages to the backend storage.   It reads messages when data is available from the backend. The   default is no.
  - Fix to print detailed errors when an SSL IO routine fails via   SSL_get_error.
  - Changelog entry for:   Merge NLnetLabs#955 from buevsan: fix ipset wrong behavior. - Update testdata/ipset.tdir test for ipset fix.
  - Update the dns64_lookup.rpl test for the DNS64 fallback patch.
  - Changelog entry for DNS64 patches from Daniel Gröber.
  Fixes for dns64 fallback to plain AAAA when no A records: - Cleanup if condition. - Rename variable for readability.
  dns64: Fall back to plain AAAA query with synthall but no A records
  Fixes for dns64 readability refactoring: - Move declarations to the top for C90 compliance. - Save cycles by not calling (yet) unneeded functions. - Possible use of uninitialised value. - Consistent formatting.
  dns64: Fix misleading indentation
  dns64: Refactor handle_event checks for readability
  fix ipset wrong behavior
  - Fix NLnetLabs#954: Inconsistent RPZ handling for A record returned along with   CNAME.
  - Update pymod tests for the new Python script variable.
  - For multi Python module setups, clean previously parsed module   functions in __main__'s dictionary, if any, so that only current   module functions are registered.
  - Expose the configured listening and outgoing interfaces, if any, as   a list of strings in the Python 'config_file' class instead of the   current Swig object proxy; fixes NLnetLabs#79.
  - Expose the script filename in the Python module environment 'mod_env'   instead of the config_file structure which includes the linked list   of scripts in a multi Python module setup; fixes NLnetLabs#79.
  - Better fix for infinite loop when reading multiple lines of input on   a broken remote control socket, by treating a zero byte line the   same as transmission end. Addesses NLnetLabs#947 and NLnetLabs#948.
  Apply suggestions from code review
  - cachedb-no-store, example conf and man page documentation.
  Changelog note for NLnetLabs#944. - Merge NLnetLabs#944: Disable EDNS DO.   Disable the EDNS DO flag in upstream requests. This can be helpful   for devices that cannot handle DNSSEC information. But it should not   be enabled otherwise, because that would stop DNSSEC validation. The   DNSSEC validation would not work for Unbound itself, and also not   for downstream users. Default is no. The option   is disable-edns-do: no
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants