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

Marcel Holtmann marcel at holtmann.org
Fri Apr 10 15:26:30 PDT 2015


Hi Lennart,

>> +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.
> 
>> +static int pac_dns_resolve(duk_context *ctx) {
>> +        _cleanup_free_ char *address = NULL;
>> +        struct addrinfo hints = {};
>> +        struct addrinfo *res, *addr;
>> +        const char *hostname;
>> +        int r;
>> +
>> +        hostname = duk_require_string(ctx, 0);
>> +
>> +        hints.ai_family = AF_INET;
>> +
>> +        r = getaddrinfo(hostname, NULL, &hints, &res);
>> +        if (r != 0)
>> +                return 0;
> 
> Hm, synchronous getaddrinfo() is nasty... Please use sd-resolve for
> this, which adds asynchronous getaddrinfo() for cases like this...

you do realize that you want this synchronous. These are the magic dnsResolve and myIpAddress Javascript functions that are expected to be present when executing the PAC file. There are a few more, but they can be implemented in Javascript and don't need a C backend. These two actually need that. So you need to report the result.

Regards

Marcel



More information about the systemd-devel mailing list