/usr/include/yuma/ncx/cfg.h is in libyuma-dev 2.9-1+b2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 | /*
* Copyright (c) 2008 - 2012, Andy Bierman, All Rights Reserved.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#ifndef _H_cfg
#define _H_cfg
/* FILE: cfg.h
*********************************************************************
* *
* P U R P O S E *
* *
*********************************************************************
NCX configuration database manager
Configuration segments are stored in sequential order.
NEW YANG OBJECT MODEL
=====================
Configuration database (running, candidate, startup, etc.)
+
|
+-- (root: /)
+
|
+--- object X (netconf, security, routing, etc.)
| |
| +---- object A , B, C
|
+--- object Y
| |
| +---- object D , E
V
MODULE USAGE
============
1) call cfg_init()
2) call cfg_init_static_db for the various hard-wired databases
that need to be created by the agent
3) call cfg_apply_load_root() with the startup database contents
to load into the running config
4) call cfg_set_target() [NCX_CFGID_CANDIDATE or NCX_CFGID_RUNNING]
4a) call cfg_fill_candidate_from_running if the target is candidate;
after agt.c/load_running_config is called
5) call cfg_set_state() to setup config db access, when ready
for NETCONF operations
6) Use cfg_ok_to_* functions to test config access
7) use cfg_lock and cfg_unlock as desired to set global write locks
8) use cfg_release_locks when a session terminates
9) call cfg_cleanup() when program is terminating
*********************************************************************
* *
* C H A N G E H I S T O R Y *
* *
*********************************************************************
date init comment
----------------------------------------------------------------------
15-apr-06 abb Begun.
29-may-08 abb Converted NCX database model to simplified
YANG object model
*/
#include <xmlstring.h>
#ifndef _H_dlq
#include "dlq.h"
#endif
#ifndef _H_ncx
#include "ncx.h"
#endif
#ifndef _H_ncxconst
#include "ncxconst.h"
#endif
#ifndef _H_plock
#include "plock.h"
#endif
#ifndef _H_ses
#include "ses.h"
#endif
#ifndef _H_status
#include "status.h"
#endif
#ifndef _H_val
#include "val.h"
#endif
#ifndef _H_val_util
#include "val_util.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
/********************************************************************
* *
* C O N S T A N T S *
* *
*********************************************************************/
/* bit definitions for the cfg_template->flags field */
#define CFG_FL_TARGET bit0
#define CFG_FL_DIRTY bit1
#define CFG_INITIAL_TXID (cfg_transaction_id_t)0
/********************************************************************
* *
* T Y P E S *
* *
*********************************************************************/
/* current configuration state */
typedef enum cfg_state_t_ {
CFG_ST_NONE, /* not set */
CFG_ST_INIT, /* init in progress */
CFG_ST_READY, /* ready and no locks */
CFG_ST_PLOCK, /* partial lock active */
CFG_ST_FLOCK, /* full lock active */
CFG_ST_CLEANUP /* cleanup in progress */
} cfg_state_t;
/* classify the config source */
typedef enum cfg_source_t_ {
CFG_SRC_NONE,
CFG_SRC_INTERNAL,
CFG_SRC_NETCONF,
CFG_SRC_CLI,
CFG_SRC_SNMP,
CFG_SRC_HTTP,
CFG_SRC_OTHER
} cfg_source_t;
/* classify the config location */
typedef enum cfg_location_t_ {
CFG_LOC_NONE,
CFG_LOC_INTERNAL,
CFG_LOC_FILE,
CFG_LOC_NAMED,
CFG_LOC_LOCAL_URL,
CFG_LOC_REMOTE_URL
} cfg_location_t;
/* transaction is scoped to single session write operation on a config */
typedef uint64 cfg_transaction_id_t;
/* struct representing 1 configuration database */
typedef struct cfg_template_t_ {
ncx_cfg_t cfg_id;
cfg_location_t cfg_loc;
cfg_state_t cfg_state;
cfg_transaction_id_t last_txid;
cfg_transaction_id_t cur_txid;
xmlChar *name;
xmlChar *src_url;
xmlChar lock_time[TSTAMP_MIN_SIZE];
xmlChar last_ch_time[TSTAMP_MIN_SIZE];
uint32 flags;
ses_id_t locked_by;
cfg_source_t lock_src;
dlq_hdr_t load_errQ; /* Q of rpc_err_rec_t */
dlq_hdr_t plockQ; /* Q of plock_cb_t */
val_value_t *root; /* btyp == NCX_BT_CONTAINER */
} cfg_template_t;
/********************************************************************
* *
* F U N C T I O N S *
* *
*********************************************************************/
/********************************************************************
* FUNCTION cfg_init
*
* Initialize the config manager
*
* INPUTS:
* none
* RETURNS:
* none
*********************************************************************/
extern void
cfg_init (void);
/********************************************************************
* FUNCTION cfg_cleanup
*
* Cleanup the config manager
*
* INPUTS:
* none
* RETURNS:
* none
*********************************************************************/
extern void
cfg_cleanup (void);
/********************************************************************
* FUNCTION cfg_init_static_db
*
* Initialize the specified static configuration slot
*
* INPUTS:
* id == cfg ID to intialize
*
* RETURNS:
* status
*********************************************************************/
extern status_t
cfg_init_static_db (ncx_cfg_t cfg_id);
/********************************************************************
* FUNCTION cfg_new_template
*
* Malloc and initialize a cfg_template_t struct
*
* INPUTS:
* name == cfg name
* cfg_id == cfg ID
* RETURNS:
* malloced struct or NULL if some error
* This struct needs to be freed by the caller
*********************************************************************/
extern cfg_template_t *
cfg_new_template (const xmlChar *name,
ncx_cfg_t cfg_id);
/********************************************************************
* FUNCTION cfg_free_template
*
* Clean and free the cfg_template_t struct
*
* INPUTS:
* cfg = cfg_template_t to clean and free
* RETURNS:
* none
*********************************************************************/
extern void
cfg_free_template (cfg_template_t *cfg);
/********************************************************************
* FUNCTION cfg_set_state
*
* Change the state of the specified static config
*
* INPUTS:
* cfg_id = Config ID to change
* new_state == new config state to set
* RETURNS:
* none
*********************************************************************/
extern void
cfg_set_state (ncx_cfg_t cfg_id,
cfg_state_t new_state);
/********************************************************************
* FUNCTION cfg_get_state
*
* Get the state of the specified static config
*
* INPUTS:
* cfg_id = Config ID
* RETURNS:
* config state (CFG_ST_NONE if some error)
*********************************************************************/
extern cfg_state_t
cfg_get_state (ncx_cfg_t cfg_id);
/********************************************************************
* FUNCTION cfg_get_config
*
* Get the config struct from its name
*
* INPUTS:
* cfgname = Config Name
* RETURNS:
* pointer to config struct or NULL if not found
*********************************************************************/
extern cfg_template_t *
cfg_get_config (const xmlChar *cfgname);
/********************************************************************
* FUNCTION cfg_get_config_name
*
* Get the config name from its ID
*
* INPUTS:
* cfgid == config ID
* RETURNS:
* pointer to config name or NULL if not found
*********************************************************************/
extern const xmlChar *
cfg_get_config_name (ncx_cfg_t cfgid);
/********************************************************************
* FUNCTION cfg_get_config_id
*
* Get the config struct from its ID
*
* INPUTS:
* cfgid == config ID
* RETURNS:
* pointer to config struct or NULL if not found
*********************************************************************/
extern cfg_template_t *
cfg_get_config_id (ncx_cfg_t cfgid);
/********************************************************************
* FUNCTION cfg_set_target
*
* Set the CFG_FL_TARGET flag in the specified config
*
* INPUTS:
* cfg_id = Config ID to set as a valid target
*
*********************************************************************/
extern void
cfg_set_target (ncx_cfg_t cfg_id);
/********************************************************************
* FUNCTION cfg_fill_candidate_from_running
*
* Fill the <candidate> config with the config contents
* of the <running> config
*
* RETURNS:
* status
*********************************************************************/
extern status_t
cfg_fill_candidate_from_running (void);
/********************************************************************
* FUNCTION cfg_fill_candidate_from_startup
*
* Fill the <candidate> config with the config contents
* of the <startup> config
*
* RETURNS:
* status
*********************************************************************/
extern status_t
cfg_fill_candidate_from_startup (void);
/********************************************************************
* FUNCTION cfg_fill_candidate_from_inline
*
* Fill the <candidate> config with the config contents
* of the <config> inline XML node
*
* INPUTS:
* newroot == new root for the candidate config
*
* RETURNS:
* status
*********************************************************************/
extern status_t
cfg_fill_candidate_from_inline (val_value_t *newroot);
/********************************************************************
* FUNCTION cfg_set_dirty_flag
*
* Mark the config as 'changed'
*
* INPUTS:
* cfg == configuration template to set
*
*********************************************************************/
extern void
cfg_set_dirty_flag (cfg_template_t *cfg);
/********************************************************************
* FUNCTION cfg_get_dirty_flag
*
* Get the config dirty flag value
*
* INPUTS:
* cfg == configuration template to check
*
*********************************************************************/
extern boolean
cfg_get_dirty_flag (const cfg_template_t *cfg);
/********************************************************************
* FUNCTION cfg_ok_to_lock
*
* Check if the specified config can be locked right now
* for global lock only
*
* INPUTS:
* cfg = Config template to check
*
* RETURNS:
* status
*********************************************************************/
extern status_t
cfg_ok_to_lock (const cfg_template_t *cfg);
/********************************************************************
* FUNCTION cfg_ok_to_unlock
*
* Check if the specified config can be unlocked right now
* by the specified session ID; for global lock only
*
* INPUTS:
* cfg = Config template to check
* sesid == session ID requesting to unlock the config
* RETURNS:
* status
*********************************************************************/
extern status_t
cfg_ok_to_unlock (const cfg_template_t *cfg,
ses_id_t sesid);
/********************************************************************
* FUNCTION cfg_ok_to_read
*
* Check if the specified config can be read right now
*
* INPUTS:
* cfg = Config template to check
* RETURNS:
* status
*********************************************************************/
extern status_t
cfg_ok_to_read (const cfg_template_t *cfg);
/********************************************************************
* FUNCTION cfg_ok_to_write
*
* Check if the specified config can be written right now
* by the specified session ID
*
* This is not an access control check,
* only locks and config state will be checked
*
* INPUTS:
* cfg = Config template to check
* sesid == session ID requesting to write to the config
* RETURNS:
* status
*********************************************************************/
extern status_t
cfg_ok_to_write (const cfg_template_t *cfg,
ses_id_t sesid);
/********************************************************************
* FUNCTION cfg_is_global_locked
*
* Check if the specified config has ab active global lock
*
* INPUTS:
* cfg = Config template to check
*
* RETURNS:
* TRUE if global lock active, FALSE if not
*********************************************************************/
extern boolean
cfg_is_global_locked (const cfg_template_t *cfg);
/********************************************************************
* FUNCTION cfg_is_partial_locked
*
* Check if the specified config has any active partial locks
*
* INPUTS:
* cfg = Config template to check
*
* RETURNS:
* TRUE if partial lock active, FALSE if not
*********************************************************************/
extern boolean
cfg_is_partial_locked (const cfg_template_t *cfg);
/********************************************************************
* FUNCTION cfg_get_global_lock_info
*
* Get the current global lock info
*
* INPUTS:
* cfg = Config template to check
* sid == address of return session ID
* locktime == address of return locktime pointer
*
* OUTPUTS:
* *sid == session ID of lock holder
* *locktime == pointer to lock time string
*
* RETURNS:
* status, NCX_ERR_SKIPPED if not locked
*********************************************************************/
extern status_t
cfg_get_global_lock_info (const cfg_template_t *cfg,
ses_id_t *sid,
const xmlChar **locktime);
/********************************************************************
* FUNCTION cfg_lock
*
* Lock the specified config.
* This will not really have an effect unless the
* CFG_FL_TARGET flag in the specified config is also set
*
* INPUTS:
* cfg = Config template to lock
* locked_by == session ID of the lock owner
* lock_src == enum classifying the lock source
* RETURNS:
* status
*********************************************************************/
extern status_t
cfg_lock (cfg_template_t *cfg,
ses_id_t locked_by,
cfg_source_t lock_src);
/********************************************************************
* FUNCTION cfg_unlock
*
* Unlock the specified config.
*
* INPUTS:
* cfg = Config template to unlock
* locked_by == session ID of the lock owner
* RETURNS:
* status
*********************************************************************/
extern status_t
cfg_unlock (cfg_template_t *cfg,
ses_id_t locked_by);
/********************************************************************
* FUNCTION cfg_release_locks
*
* Release any configuration locks held by the specified session
*
* INPUTS:
* sesid == session ID to check for
*
*********************************************************************/
extern void
cfg_release_locks (ses_id_t sesid);
/********************************************************************
* FUNCTION cfg_release_partial_locks
*
* Release any configuration locks held by the specified session
*
* INPUTS:
* sesid == session ID to check for
*
*********************************************************************/
extern void
cfg_release_partial_locks (ses_id_t sesid);
/********************************************************************
* FUNCTION cfg_get_lock_list
*
* Get a list of all the locks held by a session
*
* INPUTS:
* sesid == session ID to check for any locks
* retval == pointer to malloced and initialized NCX_BT_SLIST
*
* OUTPUTS:
* *retval is filled in with any lock entryies or left empty
* if none found
*
*********************************************************************/
extern void
cfg_get_lock_list (ses_id_t sesid,
val_value_t *retval);
/********************************************************************
* FUNCTION cfg_apply_load_root
*
* Apply the AGT_CB_APPLY function for the OP_EDITOP_LOAD operation
*
* INPUTS:
* cfg == config target
* newroot == new config tree
*
*********************************************************************/
extern void
cfg_apply_load_root (cfg_template_t *cfg,
val_value_t *newroot);
/********************************************************************
* FUNCTION cfg_update_last_ch_time
*
* Update the last-modified timestamp
*
* INPUTS:
* cfg == config target
*********************************************************************/
extern void
cfg_update_last_ch_time (cfg_template_t *cfg);
/********************************************************************
* FUNCTION cfg_update_last_txid
*
* Update the last good transaction ID
*
* INPUTS:
* cfg == config target
* txid == trnasaction ID to use
*********************************************************************/
extern void
cfg_update_last_txid (cfg_template_t *cfg,
cfg_transaction_id_t txid);
/********************************************************************
* FUNCTION cfg_add_partial_lock
*
* Add a partial lock the specified config.
* This will not really have an effect unless the
* CFG_FL_TARGET flag in the specified config is also set
* For global lock only
*
* INPUTS:
* cfg = Config template to lock
* plcb == partial lock control block, already filled
* out, to add to this configuration
*
* RETURNS:
* status; if NO_ERR then the memory in plcb is handed off
* and will be released when cfg_remove_partial_lock
* is called for 'plcb'
*********************************************************************/
extern status_t
cfg_add_partial_lock (cfg_template_t *cfg,
plock_cb_t *plcb);
/********************************************************************
* FUNCTION cfg_find_partial_lock
*
* Find a partial lock in the specified config.
*
* INPUTS:
* cfg = Config template to use
* lockid == lock-id for the plcb to find
*
* RETURNS:
* pointer to the partial lock control block found
* NULL if not found
*********************************************************************/
extern plock_cb_t *
cfg_find_partial_lock (cfg_template_t *cfg,
plock_id_t lockid);
/********************************************************************
* FUNCTION cfg_first_partial_lock
*
* Get the first partial lock in the specified config.
*
* INPUTS:
* cfg = Config template to use
*
* RETURNS:
* pointer to the first partial lock control block
* NULL if none exist at this time
*********************************************************************/
extern plock_cb_t *
cfg_first_partial_lock (cfg_template_t *cfg);
/********************************************************************
* FUNCTION cfg_next_partial_lock
*
* Get the next partial lock in the specified config.
*
* INPUTS:
* curplockcb == current lock control block; get next CB
*
* RETURNS:
* pointer to the next partial lock control block
* NULL if none exist at this time
*********************************************************************/
extern plock_cb_t *
cfg_next_partial_lock (plock_cb_t *curplockcb);
/********************************************************************
* FUNCTION cfg_delete_partial_lock
*
* Remove a partial lock from the specified config.
*
* INPUTS:
* cfg = Config template to use
* lockid == lock-id for the plcb to remove
*
*********************************************************************/
extern void
cfg_delete_partial_lock (cfg_template_t *cfg,
plock_id_t lockid);
/********************************************************************
* FUNCTION cfg_ok_to_partial_lock
*
* Check if the specified config can be locked right now
* for partial lock only
*
* INPUTS:
* cfg = Config template to check
*
* RETURNS:
* status
*********************************************************************/
extern status_t
cfg_ok_to_partial_lock (const cfg_template_t *cfg);
/********************************************************************
* FUNCTION cfg_get_root
*
* Get the config root for the specified config
*
* INPUTS:
* cfgid == config ID to get root from
*
* RETURNS:
* config root or NULL if none or error
*********************************************************************/
extern val_value_t *
cfg_get_root (ncx_cfg_t cfgid);
#ifdef __cplusplus
} /* end extern 'C' */
#endif
#endif /* _H_cfg */
|