Hi,
Ran this little test below on a couple of our PPC targets. The test passed as described below.
Perhaps you can run this test on your target too and let us know the result?
$ ls
Makefile check_idref.c confd.conf ytypes.yang
$ cat Makefile | grep -B 5 "check_idref -t"
start: stop
$(CONFD) -c ./confd.conf $(CONFD_FLAGS)
### * Setting configuration and running identityref test now:
confd_cmd -d -d -c 'mset /types/idref "des"'
confd_cmd -d -d -c 'mset /types/idref2 "aes"'
./check_idref -t
$ cat ytypes.yang
module ytypes {
namespace "http://tail-f.com/test/ytypes";
prefix ytypes;
revision "2010-06-08";
typedef crypto-id {
type identityref {
base crypto-alg;
}
}
identity crypto-alg;
identity des {
base crypto-alg;
}
identity aes {
base crypto-alg;
}
container types {
leaf idref {
type crypto-id;
}
leaf idref2 {
type crypto-id;
}
}
}
$ cat check_idref.c
#include <netdb.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <confd.h>
#include <confd_cdb.h>
#include "ytypes.h"
#define OK(cond) do { \
int _ret = (cond); \
if (_ret != CONFD_OK) { \
fprintf(stderr, "retval=%d errno=%d lasterr=%s\n", \
_ret, confd_errno, confd_lasterr()); \
assert(_ret == CONFD_OK); \
} } while (0)
#define ERR(cond, err) (assert((cond) == CONFD_ERR && (err) == confd_errno))
static int debuglevel = CONFD_SILENT;
struct addrinfo *addr = NULL;
static struct {
u_int32_t ns;
u_int32_t tag;
char *typename;
char *in;
} typeval[] = {
{ ytypes__ns, ytypes_idref, "crypto-id", "des" },
{ ytypes__ns, ytypes_idref2, "crypto-id", "aes" }
};
static int ntypes = sizeof(typeval)/sizeof(typeval[0]);
void check_type()
{
int i;
confd_value_t v1, v2;
char val[BUFSIZ];
char path[BUFSIZ];
int len;
char *p;
struct confd_type *type;
int s;
confd_hkeypath_t kp;
u_int32_t hashed_types;
assert((s = socket(PF_INET, SOCK_STREAM, 0)) >= 0);
OK(cdb_connect(s, CDB_DATA_SOCKET, addr->ai_addr, addr->ai_addrlen));
OK(cdb_start_session(s, CDB_RUNNING));
for (i = 0; i < ntypes; i++) {
kp.len = 2;
hashed_types = confd_str2hash("types");
CONFD_SET_XMLTAG(&kp.v[1][0], hashed_types, typeval[i].ns);
CONFD_SET_XMLTAG(&kp.v[0][0], typeval[i].tag, typeval[i].ns);
confd_pp_kpath(path, sizeof(path), &kp);
fprintf(stderr, "cdb_get() -->v1 from path: %s\n", path);
OK(cdb_get(s, &v1, "%h", &kp));
type = confd_find_ns_type(typeval[i].ns, typeval[i].typename);
len = confd_val2str(type, &v1, val, sizeof(val));
fprintf(stderr, "confd_val2str v1: %s\n", &val[0]);
fprintf(stderr, "confd_str2val -->v2: %s\n", typeval[i].in);
OK(confd_str2val(type, typeval[i].in, &v2));
fprintf(stderr, "testing assert(confd_val_eq(&v1, &v2))\n");
assert(confd_val_eq(&v1, &v2));
switch (typeval[i].tag) {
case ytypes_idref:
case ytypes_idref2:
/* value is an enum or identityref (or boolean),
confd_val2str_ptr() should work */
p = confd_val2str_ptr(type, &v1);
fprintf(stderr, "confd_val2str_ptr v2: %s\n", p);
assert(p != NULL);
assert(strcmp(p, val) == 0);
break;
default:
break;
}
confd_free_value(&v1);
confd_free_value(&v2);
}
cdb_close(s);
}
int main(int argc, char **argv)
{
int c, i;
char confd_port[16];
struct addrinfo hints;
snprintf(confd_port, sizeof(confd_port), "%d", CONFD_PORT);
memset(&hints, 0, sizeof(hints));
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
while ((c = getopt(argc, argv, "dtp")) != -1) {
switch (c) {
case 'd':
debuglevel = CONFD_DEBUG;
break;
case 't':
debuglevel = CONFD_TRACE;
break;
case 'p':
debuglevel = CONFD_PROTO_TRACE;
break;
default:
fprintf(stderr,
"Usage: %s [-dtp]\n",
argv[0]);
exit(1);
}
}
confd_init("iftest", stderr, debuglevel);
if (addr == NULL &&
(i = getaddrinfo("127.0.0.1", confd_port, &hints, &addr)) != 0)
/* "Can't happen" */
confd_fatal("%s: Failed to get address for ConfD: %s\n",
argv[0], gai_strerror(i));
OK(confd_load_schemas(addr->ai_addr, addr->ai_addrlen));
check_type();
return 0;
}
$ make all start
/Users/tailf/confd-6.2/bin/confdc --fail-on-warnings -c -o ytypes.fxs ytypes.yang
/Users/tailf/confd-6.2/bin/confdc --emit-h ytypes.h ytypes.fxs
cc -c -o check_idref.o check_idref.c -Wall -g -I/Users/tailf/releases/../confd-6.2-orig/include -I/opt/local/include
cc -o check_idref check_idref.o /Users/tailf/confd-6.2/lib/libconfd.a -lpthread -lm -L/opt/local/lib
mkdir -p ./confd-cdb
cp /Users/tailf/confd-6.2/var/confd/cdb/aaa_init.xml ./confd-cdb
ln -s /Users/tailf/confd-6.2/etc/confd/ssh ssh-keydir
Build complete
### Killing any confd daemon and simple_cdb confd agents
/Users/tailf/releases/confd-6.2/bin/confd --stop || true
killall check_idref || true
No matching processes belonging to you were found
/Users/tailf/releases/confd-6.2/bin/confd -c ./confd.conf --addloadpath /Users/tailf/confd-6.2-orig/etc/confd
### * Setting configuration and running identityref test now:
confd_cmd -d -d -c 'mset /types/idref "des"'
mset "/types/idref" "des"
CMD_MAAPI is true [mtid = 0]
TRACE Connected (maapi) to ConfD
TRACE MAAPI_START_USER_SESSION --> CONFD_OK
TRACE MAAPI_START_TRANS --> CONFD_OK
TRACE MAAPI_SET_ELEM2 /types/idref --> CONFD_OK
TRACE MAAPI_APPLY_TRANS --> CONFD_OK
TRACE MAAPI_STOP_TRANS --> CONFD_OK
TRACE MAAPI_END_USER_SESSION --> CONFD_OK
confd_cmd -d -d -c 'mset /types/idref2 "aes"'
mset "/types/idref2" "aes"
CMD_MAAPI is true [mtid = 0]
TRACE Connected (maapi) to ConfD
TRACE MAAPI_START_USER_SESSION --> CONFD_OK
TRACE MAAPI_START_TRANS --> CONFD_OK
TRACE MAAPI_SET_ELEM2 /types/idref2 --> CONFD_OK
TRACE MAAPI_APPLY_TRANS --> CONFD_OK
TRACE MAAPI_STOP_TRANS --> CONFD_OK
TRACE MAAPI_END_USER_SESSION --> CONFD_OK
./check_idref -t
TRACE Connected (maapi) to ConfD
TRACE MAAPI_LOAD_ALL_NS
TRACE MAAPI_LOAD_HASH_DB
TRACE Connected (cdb) to ConfD
TRACE CDB_NEW_SESSION --> CONFD_OK
TRACE Established new CDB session to ConfD
cdb_get() -->v1 from path: /types/idref
TRACE CDB_GET /ytypes:types/idref --> CONFD_OK
confd_val2str v1: ytypes:des
confd_str2val -->v2: des
testing assert(confd_val_eq(&v1, &v2))
confd_val2str_ptr v2: ytypes:des
cdb_get() -->v1 from path: /types/idref2
TRACE CDB_GET /ytypes:types/idref2 --> CONFD_OK
confd_val2str v1: ytypes:aes
confd_str2val -->v2: aes
testing assert(confd_val_eq(&v1, &v2))
confd_val2str_ptr v2: ytypes:aes