virdnsmasq.h 4.0 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 24 25 26
 *
 * based on iptables.h
 */

#ifndef __DNSMASQ_H__
# define __DNSMASQ_H__

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

S
Satoru SATOH 已提交
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
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
{
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
    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
{
66
    char                 *config_dir;
67 68
    dnsmasqHostsfile     *hostsfile;
    dnsmasqAddnHostsfile *addnhostsfile;
S
Satoru SATOH 已提交
69 70
} dnsmasqContext;

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

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

typedef struct _dnsmasqCaps dnsmasqCaps;
typedef dnsmasqCaps *dnsmasqCapsPtr;


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

99 100 101 102 103 104 105 106 107
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 已提交
108 109 110 111 112 113 114 115 116 117 118 119 120 121

# define DNSMASQ_DHCPv6_MAJOR_REQD 2
# define DNSMASQ_DHCPv6_MINOR_REQD 64
# define DNSMASQ_RA_MAJOR_REQD 2
# define DNSMASQ_RA_MINOR_REQD 64

# define DNSMASQ_DHCPv6_SUPPORT(CAPS)        \
    (dnsmasqCapsGetVersion(CAPS) >=          \
     (DNSMASQ_DHCPv6_MAJOR_REQD * 1000000) + \
     (DNSMASQ_DHCPv6_MINOR_REQD * 1000))
# define DNSMASQ_RA_SUPPORT(CAPS)            \
    (dnsmasqCapsGetVersion(CAPS) >=          \
     (DNSMASQ_RA_MAJOR_REQD * 1000000) +     \
     (DNSMASQ_RA_MINOR_REQD * 1000))
S
Satoru SATOH 已提交
122
#endif /* __DNSMASQ_H__ */