[systemd-devel] [RFC 3/6] proxy-discoveryd: Add PAC support through duktape js engine

Tomasz Bursztyka tomasz.bursztyka at linux.intel.com
Mon Apr 13 04:30:44 PDT 2015


Le 10/04/2015 18:49, Lennart Poettering a écrit :
> On Fri, 10.04.15 15:17, Tomasz Bursztyka (tomasz.bursztyka at linux.intel.com) wrote:
>
>> +struct PAC {
>> +        duk_context *ctx;
>> +};
>> +
>> +static int get_addresses_from_interface(int ifindex, union in_addr_union *address) {
>> +        struct ifreq ifr = {};
>> +        int sk;
>> +
>> +        sk = socket(AF_INET, SOCK_DGRAM, 0);
>> +        if (sk < 0)
>> +                return -1;
> No made up errors please! Return -errno or so.
>
>> +
>> +        ifr.ifr_ifindex = ifindex;
>> +
>> +        if (ioctl(sk, SIOCGIFNAME, &ifr) < 0 || ioctl(sk, SIOCGIFADDR, &ifr) < 0) {
>> +                close(sk);
>> +                return -1;
> Same here...
>
> Also, please don't use the old ioctls for querying network
> information. Use netlink through sd-rtnl. You can look at the
> systemd-resolved sources, they do this already, and this code should
> probably do it very similar from that.

Yes, it was just to get something working as a PoC. But nothing to be 
pushed.
I started to work on an sd-rtnl part that will keep track of the 
interfaces, their IPs and
which one it tight to the default route.

>> +static int create_context(struct PAC *pac, char *pac_file, void *user_data) {
>> +        duk_context *ctx;
>> +
>> +        ctx = duk_create_heap(NULL, NULL, NULL, NULL, NULL);
>> +        if (!ctx)
>> +                return -ENOMEM;
>> +
>> +        duk_push_global_object(ctx);
>> +        duk_push_c_function(ctx, pac_dns_resolve, 1);
>> +        duk_put_prop_string(ctx, -2, "dnsResolve");
>> +        duk_push_c_function(ctx, pac_my_ip_address, 0);
>> +        duk_put_prop_string(ctx, -2, "myIpAddress");
>> +
>> +        duk_push_pointer(ctx, user_data);
>> +        duk_put_prop_string(ctx, -2, "_user_data_");
>> +
>> +        duk_pop(ctx);
>> +
>> +        if (duk_peval_file(ctx, pac_file) != 0) {
>> +                duk_destroy_heap(ctx);
>> +                return -EINVAL;
>> +        }
> How is error handling done in duktape? The individual functions cannot
> fail? And are any errors returned?

There are yes. Let's use them. I'll also hook the internal duktape 
failure functions etc...

And I'll apply the other comments as well

Tomasz


More information about the systemd-devel mailing list