virdnsmasq.h 3.9 KB
Newer Older
S
Satoru SATOH 已提交
1
/*
2 3
 * virdnsmasq.h: Helper APIs for managing dnsmasq
 *
4
 * Copyright (C) 2007-2012 Red Hat, Inc.
S
Satoru SATOH 已提交
5 6 7 8 9 10 11 12 13 14 15 16 17
 * Copyright (C) 2010 Satoru SATOH <satoru.satoh@gmail.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with this library.  If not, see
O
Osier Yang 已提交
19
 * <http://www.gnu.org/licenses/>.
S
Satoru SATOH 已提交
20 21 22 23
 *
 * based on iptables.h
 */

24
#pragma once
S
Satoru SATOH 已提交
25

26 27
#include "virobject.h"
#include "virsocketaddr.h"
28

S
Satoru SATOH 已提交
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
typedef struct
{
    /*
     * Each entry holds a string, "<mac_addr>,<hostname>,<ip_addr>" such as
     * "01:23:45:67:89:0a,foo,10.0.0.3".
     */
    char *host;

} dnsmasqDhcpHost;

typedef struct
{
    unsigned int     nhosts;
    dnsmasqDhcpHost *hosts;

    char            *path;  /* Absolute path of dnsmasq's hostsfile. */
} dnsmasqHostsfile;

typedef struct
{
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
    unsigned int    nhostnames;
    char            *ip;
    char            **hostnames;

} dnsmasqAddnHost;

typedef struct
{
    unsigned int     nhosts;
    dnsmasqAddnHost *hosts;

    char            *path;  /* Absolute path of dnsmasq's hostsfile. */
} dnsmasqAddnHostsfile;

typedef struct
{
65
    char                 *config_dir;
66 67
    dnsmasqHostsfile     *hostsfile;
    dnsmasqAddnHostsfile *addnhostsfile;
S
Satoru SATOH 已提交
68 69
} dnsmasqContext;

70 71
typedef enum {
   DNSMASQ_CAPS_BIND_DYNAMIC = 0, /* support for --bind-dynamic */
72
   DNSMASQ_CAPS_BINDTODEVICE = 1, /* uses SO_BINDTODEVICE for --bind-interfaces */
73
   DNSMASQ_CAPS_RA_PARAM = 2,     /* support for --ra-param */
74 75 76 77 78 79 80 81

   DNSMASQ_CAPS_LAST,             /* this must always be the last item */
} dnsmasqCapsFlags;

typedef struct _dnsmasqCaps dnsmasqCaps;
typedef dnsmasqCaps *dnsmasqCapsPtr;


S
Satoru SATOH 已提交
82 83 84
dnsmasqContext * dnsmasqContextNew(const char *network_name,
                                   const char *config_dir);
void             dnsmasqContextFree(dnsmasqContext *ctx);
85
int              dnsmasqAddDhcpHost(dnsmasqContext *ctx,
S
Satoru SATOH 已提交
86
                                    const char *mac,
87
                                    virSocketAddr *ip,
G
Gene Czarcinski 已提交
88
                                    const char *name,
89
                                    const char *id,
G
Gene Czarcinski 已提交
90
                                    bool ipv6);
91
int              dnsmasqAddHost(dnsmasqContext *ctx,
92 93
                                virSocketAddr *ip,
                                const char *name);
S
Satoru SATOH 已提交
94 95 96 97
int              dnsmasqSave(const dnsmasqContext *ctx);
int              dnsmasqDelete(const dnsmasqContext *ctx);
int              dnsmasqReload(pid_t pid);

98 99 100 101 102 103 104 105 106
dnsmasqCapsPtr dnsmasqCapsNewFromBuffer(const char *buf,
                                        const char *binaryPath);
dnsmasqCapsPtr dnsmasqCapsNewFromFile(const char *dataPath,
                                      const char *binaryPath);
dnsmasqCapsPtr dnsmasqCapsNewFromBinary(const char *binaryPath);
int dnsmasqCapsRefresh(dnsmasqCapsPtr *caps, const char *binaryPath);
bool dnsmasqCapsGet(dnsmasqCapsPtr caps, dnsmasqCapsFlags flag);
const char *dnsmasqCapsGetBinaryPath(dnsmasqCapsPtr caps);
unsigned long dnsmasqCapsGetVersion(dnsmasqCapsPtr caps);
G
Gene Czarcinski 已提交
107

108 109 110 111
#define DNSMASQ_DHCPv6_MAJOR_REQD 2
#define DNSMASQ_DHCPv6_MINOR_REQD 64
#define DNSMASQ_RA_MAJOR_REQD 2
#define DNSMASQ_RA_MINOR_REQD 64
G
Gene Czarcinski 已提交
112

113
#define DNSMASQ_DHCPv6_SUPPORT(CAPS) \
114
    (dnsmasqCapsGetVersion(CAPS) >= \
G
Gene Czarcinski 已提交
115 116
     (DNSMASQ_DHCPv6_MAJOR_REQD * 1000000) + \
     (DNSMASQ_DHCPv6_MINOR_REQD * 1000))
117
#define DNSMASQ_RA_SUPPORT(CAPS) \
118 119
    (dnsmasqCapsGetVersion(CAPS) >= \
     (DNSMASQ_RA_MAJOR_REQD * 1000000) + \
G
Gene Czarcinski 已提交
120
     (DNSMASQ_RA_MINOR_REQD * 1000))