summaryrefslogtreecommitdiffstats
path: root/src/providers/dp_dyndns.h
blob: e49ab8f0309bda5da6e6b00f1cb53016b88ae22c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
    SSSD

    dp_dyndns.h

    Authors:
        Jakub Hrozek <jhrozek@redhat.com>

    Copyright (C) 2013 Red Hat

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.

    This program 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 General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/


#ifndef DP_DYNDNS_H_
#define DP_DYNDNS_H_

/* dynamic dns helpers */
struct sss_iface_addr;

typedef void (*nsupdate_timer_fn_t)(void *pvt);

struct be_nsupdate_ctx {
    struct dp_option *opts;

    time_t last_refresh;
    bool timer_in_progress;
    struct tevent_timer *refresh_timer;
    nsupdate_timer_fn_t timer_callback;
    void *timer_pvt;
};

enum dp_dyndns_opts {
    DP_OPT_DYNDNS_UPDATE,
    DP_OPT_DYNDNS_REFRESH_INTERVAL,
    DP_OPT_DYNDNS_IFACE,
    DP_OPT_DYNDNS_TTL,

    DP_OPT_DYNDNS /* attrs counter */
};

#define DYNDNS_REMOVE_A     0x1
#define DYNDNS_REMOVE_AAAA  0x2

errno_t be_nsupdate_check(void);

errno_t
be_nsupdate_init(TALLOC_CTX *mem_ctx, struct be_ctx *be_ctx,
                 struct dp_option *defopts,
                 nsupdate_timer_fn_t timer_callback,
                 void *timer_pvt,
                 struct be_nsupdate_ctx **_ctx);

void be_nsupdate_timer_schedule(struct tevent_context *ev,
                                struct be_nsupdate_ctx *ctx);

errno_t
sss_iface_addr_list_get(TALLOC_CTX *mem_ctx, const char *ifname,
                        struct sss_iface_addr **_addrlist);

struct sss_iface_addr *
sss_iface_addr_add(TALLOC_CTX *mem_ctx, struct sss_iface_addr **list,
                   struct sockaddr_storage *ss);

errno_t
sss_iface_addr_list_as_str_list(TALLOC_CTX *mem_ctx,
                                struct sss_iface_addr *ifaddr_list,
                                char ***_straddrs);

errno_t
be_nsupdate_create_msg(TALLOC_CTX *mem_ctx, const char *realm,
                       const char *zone, const char *servername,
                       const char *hostname, const unsigned int ttl,
                       uint8_t remove_af, struct sss_iface_addr *addresses,
                       char **_update_msg);

/* Returns:
 *    * ERR_OK              - on success
 *    * ERR_DYNDNS_FAILED   - if nsupdate fails for any reason
 *    * ERR_DYNDNS_TIMEOUT  - if the update times out. child_status
 *                            is ETIMEDOUT in this case
 */
struct tevent_req *be_nsupdate_send(TALLOC_CTX *mem_ctx,
                                    struct tevent_context *ev,
                                    char *nsupdate_msg);
errno_t be_nsupdate_recv(struct tevent_req *req, int *child_status);

struct tevent_req * nsupdate_get_addrs_send(TALLOC_CTX *mem_ctx,
                                            struct tevent_context *ev,
                                            struct be_resolv_ctx *be_res,
                                            const char *hostname);
errno_t nsupdate_get_addrs_recv(struct tevent_req *req,
                                TALLOC_CTX *mem_ctx,
                                char ***_addrlist);

#endif /* DP_DYNDNS_H_ */