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
|
/*
* This file and its contents are supplied under the terms of the
* Common Development and Distribution License ("CDDL"), version 1.0.
* You may only use this file in accordance with the terms of version
* 1.0 of the CDDL.
*
* A full copy of the text of the CDDL should have accompanied this
* source. A copy of the CDDL is also available via the Internet at
* http://www.illumos.org/license/CDDL.
*/
/*
* Copyright 2015 Joyent, Inc.
*/
/*
* Lookup functions for various file paths used by ipmgmtd. This mechanism
* primarily exists to account for a native root prefix when run within a
* branded zone (e.g. "/native").
*/
#include <stdio.h>
#include <zone.h>
#include "ipmgmt_impl.h"
#define IPADM_PERM_DIR "/etc/ipadm"
#define IPADM_TMPFS_DIR "/etc/svc/volatile/ipadm"
typedef struct ipadm_path_ent {
ipadm_path_t ipe_id;
const char *ipe_path;
} ipadm_path_ent_t;
static ipadm_path_ent_t ipadm_paths[] = {
/*
* A temporary directory created in the SMF volatile filesystem.
*/
{ IPADM_PATH_TMPFS_DIR, IPADM_TMPFS_DIR },
/*
* This file captures the in-memory copy of list `aobjmap' on disk.
* This allows the system to recover in the event that the daemon
* crashes or is restarted.
*/
{ IPADM_PATH_ADDROBJ_MAP_DB, IPADM_TMPFS_DIR "/aobjmap.conf" },
/*
* The permanent data store for ipadm.
*/
{ IPADM_PATH_DB, IPADM_PERM_DIR "/ipadm.conf" },
/*
* A temporary copy of the ipadm configuration created, if needed, to
* service write requests early in boot. This file is merged with the
* permanent data store once it is available for writes.
*/
{ IPADM_PATH_VOL_DB, IPADM_TMPFS_DIR "/ipadm.conf" },
{ 0, NULL }
};
/*
* Load one of the paths used by ipadm into the provided string buffer.
* Prepends the native system prefix (e.g. "/native") if one is in effect,
* such as when running within a branded zone.
*/
void
ipmgmt_path(ipadm_path_t ip, char *buf, size_t bufsz)
{
int i;
for (i = 0; ipadm_paths[i].ipe_path != NULL; i++) {
if (ipadm_paths[i].ipe_id == ip) {
const char *zroot = zone_get_nroot();
(void) snprintf(buf, bufsz, "%s%s", zroot != NULL ?
zroot : "", ipadm_paths[i].ipe_path);
return;
}
}
abort();
}
|