CliXoN
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Macros | Functions | Variables
clixon_yang_type.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <limits.h>
#include <ctype.h>
#include <string.h>
#include <arpa/inet.h>
#include <regex.h>
#include <syslog.h>
#include <assert.h>
#include <netinet/in.h>
#include <cligen/cligen.h>
#include "clixon_log.h"
#include "clixon_err.h"
#include "clixon_string.h"
#include "clixon_queue.h"
#include "clixon_hash.h"
#include "clixon_handle.h"
#include "clixon_yang.h"
#include "clixon_chunk.h"
#include "clixon_options.h"
#include "clixon_yang_type.h"

Macros

#define __USE_GNU   /* strverscmp */
 
#define range_check(i, rmin, rmax, type)
 

Functions

int yang_type_cache_set (yang_type_cache **ycache0, yang_stmt *resolved, int options, cg_var *mincv, cg_var *maxcv, char *pattern, uint8_t fraction)
 
int yang_type_cache_get (yang_type_cache *ycache, yang_stmt **resolved, int *options, cg_var **mincv, cg_var **maxcv, char **pattern, uint8_t *fraction)
 
int yang_type_cache_cp (yang_type_cache **ycnew, yang_type_cache *ycold)
 
int yang_type_cache_free (yang_type_cache *ycache)
 
int ys_resolve_type (yang_stmt *ys, void *arg)
 
static int yang_builtin (char *type)
 
int yang2cv_type (char *ytype, enum cv_type *cv_type)
 
char * cv2yang_type (enum cv_type cv_type)
 
int clicon_type2cv (char *origtype, char *restype, enum cv_type *cvtype)
 
static int cv_validate1 (cg_var *cv, enum cv_type cvtype, int options, cg_var *range_min, cg_var *range_max, char *pattern, yang_stmt *yrestype, char *restype, char **reason)
 
int ys_cv_validate (cg_var *cv, yang_stmt *ys, char **reason)
 
static int ys_typedef (yang_stmt *ys)
 
static yang_stmt * ys_typedef_up (yang_stmt *ys)
 
yang_stmt * yang_find_identity (yang_stmt *ys, char *identity)
 
static int resolve_restrictions (yang_stmt *yrange, yang_stmt *ylength, yang_stmt *ypattern, yang_stmt *yfraction, int *options, cg_var **mincv, cg_var **maxcv, char **pattern, uint8_t *fraction)
 
int yang_type_resolve (yang_stmt *ys, yang_stmt *ytype, yang_stmt **yrestype, int *options, cg_var **mincv, cg_var **maxcv, char **pattern, uint8_t *fraction)
 
int yang_type_get (yang_stmt *ys, char **origtype, yang_stmt **yrestype, int *options, cg_var **mincv, cg_var **maxcv, char **pattern, uint8_t *fraction)
 

Variables

struct map_str2int _YYERROR
 
static const struct map_str2int ytmap []
 

Macro Definition Documentation

#define __USE_GNU   /* strverscmp */
#define range_check (   i,
  rmin,
  rmax,
  type 
)
Value:
((rmin && (i) < cv_##type##_get(rmin)) || \
(rmax && (i) > cv_##type##_get(rmax)))
< KEYWORD > type
Definition: clixon_yang_parse.l:172

Function Documentation

int clicon_type2cv ( char *  origtype,
char *  restype,
enum cv_type *  cvtype 
)

Translate from yang type -> cligen type, after yang resolve has been made. handle case where yang resolve did not succedd (rtype=NULL) and then try to find special cligen types such as ipv4addr. not true yang types

Parameters
[in]origtype
[in]restype
[out]cvtype
char* cv2yang_type ( enum cv_type  cv_type)

Translate from a cligen variable type to a yang type

static int cv_validate1 ( cg_var *  cv,
enum cv_type  cvtype,
int  options,
cg_var *  range_min,
cg_var *  range_max,
char *  pattern,
yang_stmt *  yrestype,
char *  restype,
char **  reason 
)
static
Return values
-1Error (fatal), with errno set to indicate error
0Validation not OK, malloced reason is returned. Free reason with free()
1Validation OK
static int resolve_restrictions ( yang_stmt *  yrange,
yang_stmt *  ylength,
yang_stmt *  ypattern,
yang_stmt *  yfraction,
int *  options,
cg_var **  mincv,
cg_var **  maxcv,
char **  pattern,
uint8_t *  fraction 
)
static
int yang2cv_type ( char *  ytype,
enum cv_type *  cv_type 
)

Translate from a yang type to a cligen variable type

Currently many built-in types from RFC6020 and some RFC6991 types. But not all, neither built-in nor 6991. Also, there is no support for derived types, eg yang typedefs. See 4.2.4 in RFC6020 Return 0 if no match but set cv_type to CGV_ERR

static int yang_builtin ( char *  type)
static
yang_stmt* yang_find_identity ( yang_stmt *  ys,
char *  identity 
)

Return yang-stmt of identity This is a sanity check of base identity of identity-ref and for identity statements.

Return true if node is identityref and is derived from identity_name The derived-from() function returns true if the (first) node (in document order in the argument "nodes") is a node of type identityref, and its value is an identity that is derived from the identity "identity-name" defined in the YANG module "module-name"; otherwise it returns false.

Valid values for an identityref are any identities derived from the identityref's base identity.

  1. (base) identity must exist (be found). This is a sanity check of the specification and also necessary for identity statements.
  2. Check if a given node has value derived from base identity. This is a run-time check necessary when validating eg netconf.
  3. Find all valid derived identities from a identityref base identity. This is for cli generation. Så vad är det denna function ska göra? Svar: 1
int yang_type_cache_cp ( yang_type_cache **  ycnew,
yang_type_cache *  ycold 
)
int yang_type_cache_free ( yang_type_cache *  ycache)
int yang_type_cache_get ( yang_type_cache *  ycache,
yang_stmt **  resolved,
int *  options,
cg_var **  mincv,
cg_var **  maxcv,
char **  pattern,
uint8_t *  fraction 
)

Get individual fields (direct/destrucively) from yang type cache.

int yang_type_cache_set ( yang_type_cache **  ycache0,
yang_stmt *  resolved,
int  options,
cg_var *  mincv,
cg_var *  maxcv,
char *  pattern,
uint8_t  fraction 
)
int yang_type_get ( yang_stmt *  ys,
char **  origtype,
yang_stmt **  yrestype,
int *  options,
cg_var **  mincv,
cg_var **  maxcv,
char **  pattern,
uint8_t *  fraction 
)

Get type information about a leaf/leaf-list yang-statement

yang_stmt *yrestype;
int options;
int64_t min, max;
char *pattern;
uint8_t fraction;
if (yang_type_get(ys, &type, &yrestype, &options, &min, &max, &pattern, &fraction) < 0)
goto err;
if (yrestype == NULL) # unresolved
goto err;
if (options & YANG_OPTIONS_LENGTH != 0)
printf("%d..%d\n", min , max);
if (options & YANG_OPTIONS_PATTERN != 0)
printf("regexp: %s\n", pattern);
Parameters
[in]ysyang-stmt, leaf or leaf-list
[out]origtypeoriginal type may be derived or built-in
[out]yrestypepointer to resolved type stmt. should be built-in or NULL
[out]optionspointer to flags field of optional values
[out]mincvpointer to cv of min range or length. optional
[out]maxcvpointer to cv of max range or length. optional
[out]patternpointer to static string of yang string pattern. optional
[out]fractionfor decimal64, how many digits after period
Return values
0OK, but note that restype==NULL means not resolved.
-1Error, clicon_err handles errors The setting of the options argument has the following semantics: options&YANG_OPTIONS_RANGE or YANG_OPTIONS_LENGTH –> mincv and max can be set options&YANG_OPTIONS_PATTERN –> pattern is set options&YANG_OPTIONS_FRACTION_DIGITS –> fraction is set Note that the static output strings (type, pattern) should be copied if used asap. Note also that for all pointer arguments, if NULL is given, no value is assigned. yang_type_resolve(). This function is really just a frontend to that.
int yang_type_resolve ( yang_stmt *  ys,
yang_stmt *  ytype,
yang_stmt **  yrestype,
int *  options,
cg_var **  mincv,
cg_var **  maxcv,
char **  pattern,
uint8_t *  fraction 
)

Recursively resolve a yang type to built-in type with optional restrictions

Parameters
[in]ysyang-stmt from where the current search is based
[in]ytypeyang-stmt object containing currently resolving type
[out]yrestyperesolved type. return built-in type or NULL. mandatory
[out]optionspointer to flags field of optional values. optional
[out]mincvpointer to cv with min range or length. If options&YANG_OPTIONS_RANGE
[out]maxcvpointer to cv with max range or length. If options&YANG_OPTIONS_RANGE
[out]patternpointer to static string of yang string pattern. optional
[out]fractionfor decimal64, how many digits after period
Return values
0OK. Note yrestype may still be NULL.
-1Error, clicon_err handles errors The setting of the options argument has the following semantics: options&YANG_OPTIONS_RANGE or YANG_OPTIONS_LENGTH –> mincv and max can be set options&YANG_OPTIONS_PATTERN –> pattern is set options&YANG_OPTIONS_FRACTION_DIGITS –> fraction is set Note that the static output strings (type, pattern) should be copied if used asap. Note also that for all pointer arguments, if NULL is given, no value is assigned.
int ys_cv_validate ( cg_var *  cv,
yang_stmt *  ys,
char **  reason 
)

Validate cligen variable cv using yang statement as spec

Parameters
[in]cvA cligen variable to validate. This is a correctly parsed cv.
[in]ysA yang statement, must be leaf of leaf-list.
[out]reasonIf given, and if return value is 0, contains a malloced string describing the reason why the validation failed. Must be freed.
Return values
-1Error (fatal), with errno set to indicate error
0Validation not OK, malloced reason is returned. Free reason with free()
1Validation OK See also cv_validate - the code is similar.
int ys_resolve_type ( yang_stmt *  ys,
void *  arg 
)

Resolve types: populate type caches

static int ys_typedef ( yang_stmt *  ys)
inlinestatic
static yang_stmt* ys_typedef_up ( yang_stmt *  ys)
static

Variable Documentation

struct map_str2int _YYERROR
const struct map_str2int ytmap[]
static
Initial value:
= {
{"int32", CGV_INT32},
{"string", CGV_STRING},
{"string", CGV_REST},
{"binary", CGV_STRING},
{"bits", CGV_STRING},
{"boolean", CGV_BOOL},
{"decimal64", CGV_DEC64},
{"empty", CGV_VOID},
{"enumeration", CGV_STRING},
{"identityref", CGV_STRING},
{"instance-identifier", CGV_STRING},
{"int8", CGV_INT8},
{"int16", CGV_INT16},
{"int64", CGV_INT64},
{"leafref", CGV_STRING},
{"uint8", CGV_UINT8},
{"uint16", CGV_UINT16},
{"uint32", CGV_UINT32},
{"uint64", CGV_UINT64},
{"union", CGV_REST},
{NULL, -1}
}
input_stmt NULL
Definition: clixon_yang_parse.y:899