本文整理汇总了C++中rtnl_talk函数的典型用法代码示例。如果您正苦于以下问题:C++ rtnl_talk函数的具体用法?C++ rtnl_talk怎么用?C++ rtnl_talk使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rtnl_talk函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: restore_handler
static int restore_handler(const struct sockaddr_nl *nl, struct nlmsghdr *n, void *arg)
{
int ret;
n->nlmsg_flags |= NLM_F_REQUEST | NLM_F_CREATE | NLM_F_ACK;
ll_init_map(&rth);
ret = rtnl_talk(&rth, n, n, sizeof(*n));
if ((ret < 0) && (errno == EEXIST))
ret = 0;
return ret;
}
示例2: mpls_tunnel_add
int
mpls_tunnel_add(int cmd, unsigned flags, int argc, char **argv)
{
//__u32 labelspace = -2;
struct genlmsghdr *ghdr;
struct {
struct nlmsghdr n;
char buf[4096];
} req;
struct mpls_tunnel_req ls;
memset(&req, 0, sizeof(req));
memset(&ls, 0, sizeof(ls));
req.n.nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN);
req.n.nlmsg_flags = NLM_F_REQUEST|flags;
req.n.nlmsg_type = PF_MPLS;
ghdr = NLMSG_DATA(&req.n);
ghdr->cmd = cmd;
while (argc > 0) {
if (strcmp(*argv, "dev") == 0) {
NEXT_ARG();
//ls.mls_ifindex = ll_name_to_index(*argv);
strncpy(ls.mt_ifname, *argv, IFNAMSIZ);
} /*else if (strcmp(*argv, "labelspace") == 0) {
NEXT_ARG();
if (get_unsigned(&labelspace, *argv, 0))
invarg(*argv, "invalid labelspace");
ls.mls_labelspace = labelspace;
} */else {
usage();
}
argc--; argv++;
}
/*
if (ls.mls_ifindex == 0 || ls.mls_labelspace == -2) {
fprintf(stderr, "Invalid arguments\n");
exit(1);
}*/
addattr_l(&req.n, sizeof(req), MPLS_ATTR_TUNNEL, &ls, sizeof(ls));
if (rtnl_talk(&rth2, &req.n, 0, 0, NULL, NULL, NULL) < 0)
return 2;
//exit(2);
return 0;
}
示例3: ipoe_nl_modify
int ipoe_nl_modify(int ifindex, uint32_t peer_addr, uint32_t addr, const char *ifname, uint8_t *hwaddr)
{
struct rtnl_handle rth;
struct nlmsghdr *nlh;
struct genlmsghdr *ghdr;
int ret = 0;
struct {
struct nlmsghdr n;
char buf[1024];
} req;
union {
uint8_t hwaddr[6];
uint64_t u64;
} u;
if (rtnl_open_byproto(&rth, 0, NETLINK_GENERIC)) {
log_ppp_error("ipoe: cannot open generic netlink socket\n");
return -1;
}
nlh = &req.n;
nlh->nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN);
nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
nlh->nlmsg_type = ipoe_genl_id;
ghdr = NLMSG_DATA(&req.n);
ghdr->cmd = IPOE_CMD_MODIFY;
addattr32(nlh, 1024, IPOE_ATTR_IFINDEX, ifindex);
addattr32(nlh, 1024, IPOE_ATTR_PEER_ADDR, peer_addr);
addattr32(nlh, 1024, IPOE_ATTR_ADDR, addr);
if (hwaddr) {
memcpy(u.hwaddr, hwaddr, 6);
addattr_l(nlh, 1024, IPOE_ATTR_HWADDR, &u.u64, 8);
}
if (ifname)
addattr_l(nlh, 1024, IPOE_ATTR_IFNAME, ifname, strlen(ifname) + 1);
if (rtnl_talk(&rth, nlh, 0, 0, nlh, NULL, NULL, 0) < 0 ) {
log_ppp_error("ipoe: nl_create: error talking to kernel\n");
ret = -1;
}
rtnl_close(&rth);
return ret;
}
示例4: xfrm_policy_flush
static int xfrm_policy_flush(int argc, char **argv)
{
struct rtnl_handle rth;
struct {
struct nlmsghdr n;
char buf[RTA_BUF_SIZE];
} req;
char *ptypep = NULL;
struct xfrm_userpolicy_type upt;
memset(&req, 0, sizeof(req));
memset(&upt, 0, sizeof(upt));
req.n.nlmsg_len = NLMSG_LENGTH(0); /* nlmsg data is nothing */
req.n.nlmsg_flags = NLM_F_REQUEST;
req.n.nlmsg_type = XFRM_MSG_FLUSHPOLICY;
while (argc > 0) {
if (strcmp(*argv, "ptype") == 0) {
if (ptypep)
duparg("ptype", *argv);
ptypep = *argv;
NEXT_ARG();
xfrm_policy_ptype_parse(&upt.type, &argc, &argv);
} else
invarg("unknown", *argv);
argc--; argv++;
}
if (ptypep) {
addattr_l(&req.n, sizeof(req), XFRMA_POLICY_TYPE,
(void *)&upt, sizeof(upt));
}
if (rtnl_open_byproto(&rth, 0, NETLINK_XFRM) < 0)
exit(1);
if (show_stats > 1)
fprintf(stderr, "Flush policy\n");
if (rtnl_talk(&rth, &req.n, 0, 0, NULL, NULL, NULL) < 0)
exit(2);
rtnl_close(&rth);
return 0;
}
示例5: create_session
static int create_session(struct l2tp_parm *p)
{
GENL_REQUEST(req, 1024, genl_family, 0, L2TP_GENL_VERSION,
L2TP_CMD_SESSION_CREATE, NLM_F_REQUEST | NLM_F_ACK);
addattr32(&req.n, 1024, L2TP_ATTR_CONN_ID, p->tunnel_id);
addattr32(&req.n, 1024, L2TP_ATTR_PEER_CONN_ID, p->peer_tunnel_id);
addattr32(&req.n, 1024, L2TP_ATTR_SESSION_ID, p->session_id);
addattr32(&req.n, 1024, L2TP_ATTR_PEER_SESSION_ID, p->peer_session_id);
addattr16(&req.n, 1024, L2TP_ATTR_PW_TYPE, p->pw_type);
addattr8(&req.n, 1024, L2TP_ATTR_L2SPEC_TYPE, p->l2spec_type);
addattr8(&req.n, 1024, L2TP_ATTR_L2SPEC_LEN, p->l2spec_len);
if (p->mtu)
addattr16(&req.n, 1024, L2TP_ATTR_MTU, p->mtu);
if (p->recv_seq)
addattr8(&req.n, 1024, L2TP_ATTR_RECV_SEQ, 1);
if (p->send_seq)
addattr8(&req.n, 1024, L2TP_ATTR_SEND_SEQ, 1);
if (p->lns_mode)
addattr(&req.n, 1024, L2TP_ATTR_LNS_MODE);
if (p->data_seq)
addattr8(&req.n, 1024, L2TP_ATTR_DATA_SEQ, p->data_seq);
if (p->reorder_timeout)
addattr64(&req.n, 1024, L2TP_ATTR_RECV_TIMEOUT,
p->reorder_timeout);
if (p->offset)
addattr16(&req.n, 1024, L2TP_ATTR_OFFSET, p->offset);
if (p->cookie_len)
addattr_l(&req.n, 1024, L2TP_ATTR_COOKIE,
p->cookie, p->cookie_len);
if (p->peer_cookie_len)
addattr_l(&req.n, 1024, L2TP_ATTR_PEER_COOKIE,
p->peer_cookie, p->peer_cookie_len);
if (p->ifname)
addattrstrz(&req.n, 1024, L2TP_ATTR_IFNAME, p->ifname);
if (rtnl_talk(&genl_rth, &req.n, NULL, 0) < 0)
return -2;
return 0;
}
示例6: genl_resolve_family
int genl_resolve_family(struct rtnl_handle *grth, const char *family)
{
GENL_REQUEST(req, 1024, GENL_ID_CTRL, 0, 0, CTRL_CMD_GETFAMILY,
NLM_F_REQUEST);
struct nlmsghdr *answer;
int fnum;
addattr_l(&req.n, sizeof(req), CTRL_ATTR_FAMILY_NAME,
family, strlen(family) + 1);
if (rtnl_talk(grth, &req.n, &answer) < 0) {
fprintf(stderr, "Error talking to the kernel\n");
return -2;
}
fnum = genl_parse_getfamily(answer);
free(answer);
return fnum;
}
示例7: ipaddr_op
int ipaddr_op( int ifindex, uint32_t addr, uint8_t length, int addF )
{
struct rtnl_handle rth;
struct {
struct nlmsghdr n;
struct ifaddrmsg ifa;
char buf[256];
} req;
uint32_t bcast;
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
req.n.nlmsg_flags = NLM_F_REQUEST;
req.n.nlmsg_type = addF ? RTM_NEWADDR : RTM_DELADDR;
req.ifa.ifa_family = AF_INET;
req.ifa.ifa_index = ifindex;
req.ifa.ifa_prefixlen = 32;
req.ifa.ifa_prefixlen = length;
addr = htonl( addr );
addattr_l(&req.n, sizeof(req), IFA_LOCAL, &addr, sizeof(addr) );
bcast = addr | htonl((1 << (32 - length)) - 1);
addattr_l(&req.n, sizeof(req), IFA_BROADCAST, &bcast, sizeof(bcast) );
if (rtnl_open(&rth, 0) < 0){
rtnl_close( &rth );
return -1;
}
if (rtnl_talk(&rth, &req.n, 0, 0, NULL, NULL, NULL) < 0) {
rtnl_close( &rth );
return -1;
}
/* to close the clocket */
rtnl_close( &rth );
return(0);
}
示例8: memset
void TunManager::addRemoveTable(int ifIdx, RouterID rid, bool add) {
// We just store default routes (one for IPv4 and one for IPv6) in each route
// table.
struct {
struct nlmsghdr n;
struct rtmsg r;
char buf[256];
} req;
const folly::IPAddress addrs[] = {
IPAddress{"0.0.0.0"}, // v4 default
IPAddress{"::0"}, // v6 default
};
for (const auto& addr : addrs) {
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
req.n.nlmsg_flags = NLM_F_REQUEST;
if (add) {
req.n.nlmsg_type = RTM_NEWROUTE;
req.n.nlmsg_flags |= NLM_F_CREATE|NLM_F_REPLACE;
} else {
req.n.nlmsg_type = RTM_DELROUTE;
}
req.r.rtm_family = addr.family();
req.r.rtm_table = getTableId(rid);
req.r.rtm_scope = RT_SCOPE_NOWHERE;
req.r.rtm_protocol = RTPROT_FBOSS;
req.r.rtm_scope = RT_SCOPE_UNIVERSE;
req.r.rtm_type = RTN_UNICAST;
req.r.rtm_dst_len = 0; // default route, /0
addattr_l(&req.n, sizeof(req), RTA_DST, addr.bytes(), addr.byteCount());
addattr32(&req.n, sizeof(req), RTA_OIF, ifIdx);
auto ret = rtnl_talk(&rth_, &req.n, 0, 0, nullptr);
sysCheckError(ret, "Failed to ", add ? "add" : "remove",
" default route ", addr, " @ index ", ifIdx,
" in table ", getTableId(rid), " for router ", rid);
LOG(INFO) << (add ? "Added" : "Removed") << " default route " << addr
<< " @ index " << ifIdx << " in table " << getTableId(rid)
<< " for router " << rid;
}
}
示例9: pyrtnl_talk
static PyObject* pyrtnl_talk(PyObject* obj, PyObject* args)
{
PyRtnlObject* self = (PyRtnlObject*)obj;
char* msg;
int len;
int peer = 0;
int groups = 0;
if (!PyArg_ParseTuple(args, "s#|ii", &msg, &len, &peer, &groups))
return NULL;
if (rtnl_talk(&self->rth, (struct nlmsghdr*)msg, peer, groups, NULL, NULL,
NULL) < 0)
{
PyErr_SetString(PyExc_IOError, "error sending message");
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
示例10: flush_rule
static int flush_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
{
struct rtmsg *r = NLMSG_DATA(n);
int len = n->nlmsg_len;
struct rtattr * tb[RTA_MAX+1];
len -= NLMSG_LENGTH(sizeof(*r));
if (len < 0)
return -1;
parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len);
if (tb[RTA_PRIORITY]) {
n->nlmsg_type = RTM_DELRULE;
n->nlmsg_flags = NLM_F_REQUEST;
if (rtnl_talk(&rth, n, 0, 0, NULL, NULL, NULL) < 0)
return -2;
}
return 0;
}
示例11: create_tunnel
static int create_tunnel(struct l2tp_parm *p)
{
uint32_t local_attr = L2TP_ATTR_IP_SADDR;
uint32_t peer_attr = L2TP_ATTR_IP_DADDR;
GENL_REQUEST(req, 1024, genl_family, 0, L2TP_GENL_VERSION,
L2TP_CMD_TUNNEL_CREATE, NLM_F_REQUEST | NLM_F_ACK);
addattr32(&req.n, 1024, L2TP_ATTR_CONN_ID, p->tunnel_id);
addattr32(&req.n, 1024, L2TP_ATTR_PEER_CONN_ID, p->peer_tunnel_id);
addattr8(&req.n, 1024, L2TP_ATTR_PROTO_VERSION, 3);
addattr16(&req.n, 1024, L2TP_ATTR_ENCAP_TYPE, p->encap);
if (p->local_ip.family == AF_INET6)
local_attr = L2TP_ATTR_IP6_SADDR;
addattr_l(&req.n, 1024, local_attr, &p->local_ip.data,
p->local_ip.bytelen);
if (p->peer_ip.family == AF_INET6)
peer_attr = L2TP_ATTR_IP6_DADDR;
addattr_l(&req.n, 1024, peer_attr, &p->peer_ip.data,
p->peer_ip.bytelen);
if (p->encap == L2TP_ENCAPTYPE_UDP) {
addattr16(&req.n, 1024, L2TP_ATTR_UDP_SPORT, p->local_udp_port);
addattr16(&req.n, 1024, L2TP_ATTR_UDP_DPORT, p->peer_udp_port);
if (p->udp_csum)
addattr8(&req.n, 1024, L2TP_ATTR_UDP_CSUM, 1);
if (!p->udp6_csum_tx)
addattr(&req.n, 1024, L2TP_ATTR_UDP_ZERO_CSUM6_TX);
if (!p->udp6_csum_rx)
addattr(&req.n, 1024, L2TP_ATTR_UDP_ZERO_CSUM6_RX);
}
if (rtnl_talk(&genl_rth, &req.n, NULL, 0) < 0)
return -2;
return 0;
}
示例12: tc_action_modify
int tc_action_modify(int cmd, unsigned flags, int *argc_p, char ***argv_p)
{
int argc = *argc_p;
char **argv = *argv_p;
int ret = 0;
struct rtattr *tail;
struct {
struct nlmsghdr n;
struct tcamsg t;
char buf[MAX_MSG];
} req;
req.t.tca_family = AF_UNSPEC;
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct tcamsg));
req.n.nlmsg_flags = NLM_F_REQUEST|flags;
req.n.nlmsg_type = cmd;
tail = NLMSG_TAIL(&req.n);
argc -=1;
argv +=1;
if (parse_action(&argc, &argv, TCA_ACT_TAB, &req.n)) {
fprintf(stderr, "Illegal \"action\"\n");
return -1;
}
tail->rta_len = (void *) NLMSG_TAIL(&req.n) - (void *) tail;
if (rtnl_talk(&rth, &req.n, 0, 0, NULL) < 0) {
fprintf(stderr, "We have an error talking to the kernel\n");
ret = -1;
}
*argc_p = argc;
*argv_p = argv;
return ret;
}
示例13: modify_neigh
static int modify_neigh(struct xia_xid *dst, unsigned char *lladdr,
int lladdr_len, unsigned oif, int to_add)
{
struct {
struct nlmsghdr n;
struct rtmsg r;
char buf[1024];
} req;
memset(&req, 0, sizeof(req));
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
if (to_add) {
/* XXX Does one really needs all these flags? */
req.n.nlmsg_flags = NLM_F_REQUEST|NLM_F_CREATE|NLM_F_EXCL;
req.n.nlmsg_type = RTM_NEWROUTE;
req.r.rtm_scope = RT_SCOPE_LINK;
} else {
req.n.nlmsg_flags = NLM_F_REQUEST;
req.n.nlmsg_type = RTM_DELROUTE;
req.r.rtm_scope = RT_SCOPE_NOWHERE;
}
req.r.rtm_family = AF_XIA;
req.r.rtm_table = XRTABLE_MAIN_INDEX;
req.r.rtm_protocol = RTPROT_BOOT;
req.r.rtm_type = RTN_UNICAST;
req.r.rtm_dst_len = sizeof(*dst);
addattr_l(&req.n, sizeof(req), RTA_DST, dst, sizeof(*dst));
addattr_l(&req.n, sizeof(req), RTA_LLADDR, lladdr, lladdr_len);
addattr32(&req.n, sizeof(req), RTA_OIF, oif);
if (rtnl_talk(&rth, &req.n, 0, 0, NULL, NULL, NULL) < 0)
exit(2);
return 0;
}
示例14: ipoe_nl_add_vlan_mon_vid
int ipoe_nl_add_vlan_mon_vid(int ifindex, int vid)
{
struct rtnl_handle rth;
struct nlmsghdr *nlh;
struct genlmsghdr *ghdr;
struct {
struct nlmsghdr n;
char buf[1024];
} req;
int r = 0;
if (rtnl_open_byproto(&rth, 0, NETLINK_GENERIC)) {
log_error("ipoe: cannot open generic netlink socket\n");
return -1;
}
nlh = &req.n;
nlh->nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN);
nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
nlh->nlmsg_type = ipoe_genl_id;
ghdr = NLMSG_DATA(&req.n);
ghdr->cmd = IPOE_CMD_ADD_VLAN_MON_VID;
addattr32(nlh, 1024, IPOE_ATTR_IFINDEX, ifindex);
addattr32(nlh, 1024, IPOE_ATTR_ADDR, vid);
if (rtnl_talk(&rth, nlh, 0, 0, nlh, NULL, NULL, 0) < 0 ) {
log_error("ipoe: nl_add_vlan_mon_vid: error talking to kernel\n");
r = -1;
}
rtnl_close(&rth);
return r;
}
示例15: ipoe_nl_add_exclude
int ipoe_nl_add_exclude(uint32_t addr, int mask)
{
struct rtnl_handle rth;
struct nlmsghdr *nlh;
struct genlmsghdr *ghdr;
struct {
struct nlmsghdr n;
char buf[1024];
} req;
int ret = 0;
if (rtnl_open_byproto(&rth, 0, NETLINK_GENERIC)) {
log_ppp_error("ipoe: cannot open generic netlink socket\n");
return -1;
}
nlh = &req.n;
nlh->nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN);
nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
nlh->nlmsg_type = ipoe_genl_id;
ghdr = NLMSG_DATA(&req.n);
ghdr->cmd = IPOE_CMD_ADD_EXCLUDE;
addattr32(nlh, 1024, IPOE_ATTR_ADDR, addr);
if (rtnl_talk(&rth, nlh, 0, 0, nlh, NULL, NULL, 0) < 0 ) {
log_ppp_error("ipoe: nl_add_net: error talking to kernel\n");
ret = -1;
}
rtnl_close(&rth);
return ret;
}