LCOV - code coverage report
Current view: top level - ksync - ksync_netlink.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 61 69 88.4 %
Date: 2026-11-30 02:00:48 Functions: 6 6 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  * Copyright Contributors to the OpenSDN project
       4             :  */
       5             : 
       6             : #include <sys/types.h>
       7             : #include <sys/socket.h>
       8             : #if defined(__linux__)
       9             : #include <linux/netlink.h>
      10             : #include <linux/rtnetlink.h>
      11             : #include <linux/sockios.h>
      12             : #endif
      13             : 
      14             : #include <boost/bind/bind.hpp>
      15             : 
      16             : #include <base/logging.h>
      17             : #include <db/db.h>
      18             : #include <db/db_entry.h>
      19             : #include <db/db_table.h>
      20             : #include <db/db_table_partition.h>
      21             : 
      22             : #include <sandesh/sandesh_trace.h>
      23             : 
      24             : #include "ksync_index.h"
      25             : #include "ksync_entry.h"
      26             : #include "ksync_object.h"
      27             : #include "ksync_sock.h"
      28             : #include "ksync_types.h"
      29             : #include "ksync_netlink.h"
      30             : 
      31             : using namespace boost::placeholders;
      32             : 
      33             : ///////////////////////////////////////////////////////////////////////////////
      34             : // KSyncNetlinkEntry routines
      35             : ///////////////////////////////////////////////////////////////////////////////
      36          48 : bool KSyncNetlinkEntry::Add() {
      37          48 :     Sync();
      38          48 :     int len = MsgLen();
      39          48 :     char *msg = (char *)malloc(len);
      40          48 :     int  msg_len = AddMsg(msg, len);
      41          48 :     assert(msg_len <= len);
      42          48 :     if (msg_len == 0) {
      43           0 :         free(msg);
      44           0 :         return true;
      45             :     }
      46          48 :     KSyncSock   *sock = KSyncSock::Get(0);
      47          48 :     sock->SendAsync(this, msg_len, msg, KSyncEntry::ADD_ACK);
      48          48 :     return false;
      49             : }
      50             : 
      51          82 : bool KSyncNetlinkEntry::Change() {
      52          82 :     if (Sync() == false) {
      53          24 :         return true;
      54             :     }
      55             : 
      56          58 :     int len = MsgLen();
      57          58 :     char *msg = (char *)malloc(len);
      58          58 :     int  msg_len = ChangeMsg(msg, len);
      59          58 :     assert(msg_len <= len);
      60          58 :     if (msg_len == 0) {
      61           0 :         free(msg);
      62           0 :         return true;
      63             :     }
      64          58 :     KSyncSock   *sock = KSyncSock::Get(0);
      65          58 :     sock->SendAsync(this, msg_len, msg, KSyncEntry::CHANGE_ACK);
      66          58 :     return false;
      67             : }
      68             : 
      69          48 : bool KSyncNetlinkEntry::Delete() {
      70          48 :     int len = MsgLen();
      71          48 :     char *msg = (char *)malloc(len);
      72          48 :     int  msg_len = DeleteMsg(msg, len);
      73          48 :     assert(msg_len <= len);
      74          48 :     if (msg_len == 0) {
      75           0 :         free(msg);
      76           0 :         return true;
      77             :     }
      78          48 :     KSyncSock   *sock = KSyncSock::Get(0);
      79          48 :     sock->SendAsync(this, msg_len, msg, KSyncEntry::DEL_ACK);
      80          48 :     return false;
      81             : }
      82             : 
      83             : ///////////////////////////////////////////////////////////////////////////////
      84             : // KSyncNetlinkDBEntry routines
      85             : ///////////////////////////////////////////////////////////////////////////////
      86         381 : bool KSyncNetlinkDBEntry::Add() {
      87         381 :     int len = MsgLen();
      88         381 :     char *msg = (char *)malloc(len);
      89         381 :     int  msg_len = AddMsg(msg, len);
      90         381 :     assert(msg_len <= len);
      91         381 :     if (msg_len == 0) {
      92           2 :         free(msg);
      93           2 :         return true;
      94             :     }
      95         379 :     KSyncSock   *sock = KSyncSock::Get(0);
      96         379 :     sock->SendAsync(this, msg_len, msg, KSyncEntry::ADD_ACK);
      97         379 :     return false;
      98             : }
      99             : 
     100         107 : bool KSyncNetlinkDBEntry::Change() {
     101         107 :     int len = MsgLen();
     102         107 :     char *msg = (char *)malloc(len);
     103         107 :     int  msg_len = ChangeMsg(msg, len);
     104         107 :     assert(msg_len <= len);
     105         107 :     if (msg_len == 0) {
     106           2 :         free(msg);
     107           2 :         return true;
     108             :     }
     109         105 :     KSyncSock   *sock = KSyncSock::Get(0);
     110         105 :     sock->SendAsync(this, msg_len, msg, KSyncEntry::CHANGE_ACK);
     111         105 :     return false;
     112             : }
     113             : 
     114         381 : bool KSyncNetlinkDBEntry::Delete() {
     115         381 :     int len = MsgLen();
     116         381 :     char *msg = (char *)malloc(len);
     117         381 :     int  msg_len = DeleteMsg(msg, len);
     118         381 :     assert(msg_len <= len);
     119         381 :     if (msg_len == 0) {
     120           0 :         free(msg);
     121           0 :         return true;
     122             :     }
     123         381 :     KSyncSock   *sock = KSyncSock::Get(0);
     124         381 :     sock->SendAsync(this, msg_len, msg, KSyncEntry::DEL_ACK);
     125         381 :     return false;
     126             : }

Generated by: LCOV version 1.14