int main(int argc, char *argv[]) { char opt; int ret, option_index; while (((opt = getopt_long(argc, argv, "", long_options, &option_index)) >= 0)) { switch (opt) { case 0: break; default: Usage(); } } cl = nl_register_client(); if (!cl) { exit(1); } ret = nl_socket(cl, NETLINK_GENERIC); if (ret <= 0) { exit(1); } if (vrouter_get_family_id(cl) <= 0) { return -1; } vr_get_drop_stats(); return 0; }
static int flow_table_setup(void) { int ret; cl = nl_register_client(); if (!cl) return -ENOMEM; ret = nl_socket(cl, NETLINK_GENERIC); if (ret <= 0) return ret; ret = vrouter_get_family_id(cl); if (ret <= 0) return ret; return ret; }
int main(int argc, char *argv[]) { int ret; int opt; int ind; cl = nl_register_client(); if (!cl) { exit(1); } ret = nl_socket(cl, NETLINK_GENERIC); if (ret <= 0) { exit(1); } if (vrouter_get_family_id(cl) <= 0) { return 0; } while ((opt = getopt_long(argc, argv, "", long_options, &ind)) >= 0) { switch(opt) { case 0: parse_long_opts(ind, optarg); break; default: usage(); } } validate_options(); vr_nh_op(command, type, nh_id, if_id, vrf_id, dst_mac, src_mac, sip, dip, flags); return 0; }
int main(int argc, char *argv[]) { char opt; int ret, option_index; while (((opt = getopt_long(argc, argv, "", long_options, &option_index)) >= 0)) { switch (opt) { case 0: parse_long_opts(option_index, optarg); break; default: Usage(); } } validate_options(); cl = nl_register_client(); if (!cl) { exit(1); } ret = nl_socket(cl, NETLINK_GENERIC); if (ret <= 0) { exit(1); } if (vrouter_get_family_id(cl) <= 0) { return -1; } stats_req.vsr_marker = -1; vr_stats_op(); return 0; }
struct nl_client * vr_get_nl_client(unsigned int proto) { int ret; unsigned int sock_proto = proto; struct nl_client *cl; cl = nl_register_client(); if (!cl) return NULL; parse_ini_file(); if (proto == VR_NETLINK_PROTO_DEFAULT) sock_proto = get_protocol(); ret = nl_socket(cl, get_domain(), get_type(), sock_proto); if (ret <= 0) goto fail; ret = nl_connect(cl, get_ip(), get_port()); if (ret < 0) goto fail; if ((proto == VR_NETLINK_PROTO_DEFAULT) && (vrouter_get_family_id(cl) <= 0)) goto fail; return cl; fail: if (cl) nl_free_client(cl); return NULL; }
int nl_stream(nl_stream_t *s) { int rc; memset(s, 0, sizeof(nl_stream_t)); s->tosend = list_create(sizeof(nl_buf_t), NULL, NULL); if (s->tosend == NULL) { return -1; } rc = nl_socket(&s->sock, NL_STREAM); if (rc == -1) { list_destroy(s->tosend); s->tosend = NULL; s->error = 1; return -1; } s->id = s->sock.fd; s->sock.data = s; return 0; }
int main(int argc, char *argv[]) { int ret, opt, option_index; /* * the proto of the socket changes based on whether we are creating an * interface in linux or doing an operation in vrouter */ unsigned int sock_proto = NETLINK_GENERIC; while ((opt = getopt_long(argc, argv, "ba:c:d:g:klm:t:v:p:", long_options, &option_index)) >= 0) { switch (opt) { case 'a': add_set = 1; parse_long_opts(ADD_OPT_INDEX, optarg); break; case 'c': create_set = 1; parse_long_opts(CREATE_OPT_INDEX, optarg); break; case 'd': delete_set = 1; parse_long_opts(DELETE_OPT_INDEX, optarg); break; case 'g': get_set = 1; parse_long_opts(GET_OPT_INDEX, optarg); break; case 'k': parse_long_opts(KINDEX_OPT_INDEX, optarg); kindex_set = 1; break; case 'l': case 'b': list_set = 1; parse_long_opts(LIST_OPT_INDEX, NULL); break; case 'm': mac_set = 1; parse_long_opts(MAC_OPT_INDEX, optarg); break; case 'v': vrf_set = 1; parse_long_opts(VRF_OPT_INDEX, optarg); break; case 'p': policy_set = 1; parse_long_opts(POLICY_OPT_INDEX, NULL); break; case 't': type_set = 1; parse_long_opts(TYPE_OPT_INDEX, optarg); break; case 0: parse_long_opts(option_index, optarg); break; case '?': default: Usage(); } } validate_options(); cl = nl_register_client(); if (!cl) exit(-ENOMEM); if (create_set) sock_proto = NETLINK_ROUTE; ret = nl_socket(cl, sock_proto); if (ret <= 0) exit(ret); if (sock_proto == NETLINK_GENERIC) if (vrouter_get_family_id(cl) <= 0) return -1; if (add_set) { /* * for addition, we need to see whether the interface already * exists in vrouter or not. so, get can return error if the * interface does not exist in vrouter */ ignore_error = true; vr_intf_op(SANDESH_OP_GET); ignore_error = false; } vr_intf_op(vr_op); return 0; }