iproute2/tipc/peer.c
<<
>>
Prefs
   1/*
   2 * peer.c       TIPC peer functionality.
   3 *
   4 *              This program is free software; you can redistribute it and/or
   5 *              modify it under the terms of the GNU General Public License
   6 *              as published by the Free Software Foundation; either version
   7 *              2 of the License, or (at your option) any later version.
   8 *
   9 * Authors:     Richard Alpe <richard.alpe@ericsson.com>
  10 */
  11
  12#include <stdio.h>
  13#include <stdlib.h>
  14#include <string.h>
  15#include <errno.h>
  16
  17#include <linux/tipc_netlink.h>
  18#include <linux/tipc.h>
  19#include <linux/genetlink.h>
  20#include <libmnl/libmnl.h>
  21
  22#include "cmdl.h"
  23#include "msg.h"
  24#include "misc.h"
  25#include "peer.h"
  26
  27static int cmd_peer_rm_addr(struct nlmsghdr *nlh, const struct cmd *cmd,
  28                            struct cmdl *cmdl, void *data)
  29{
  30        char *str;
  31        uint32_t addr;
  32        struct nlattr *nest;
  33        char buf[MNL_SOCKET_BUFFER_SIZE];
  34
  35        if ((cmdl->argc != cmdl->optind + 1) || help_flag) {
  36                fprintf(stderr, "Usage: %s peer remove address ADDRESS\n",
  37                        cmdl->argv[0]);
  38                return -EINVAL;
  39        }
  40
  41        str = shift_cmdl(cmdl);
  42
  43        /* First try legacy Z.C.N format, then integer format */
  44        addr = str2addr(str);
  45        if (!addr)
  46                addr = atoi(str);
  47        if (!addr)
  48                return -1;
  49
  50        if (!(nlh = msg_init(buf, TIPC_NL_PEER_REMOVE))) {
  51                fprintf(stderr, "error, message initialisation failed\n");
  52                return -1;
  53        }
  54
  55        nest = mnl_attr_nest_start(nlh, TIPC_NLA_NET);
  56        mnl_attr_put_u32(nlh, TIPC_NLA_NET_ADDR, addr);
  57        mnl_attr_nest_end(nlh, nest);
  58
  59        return msg_doit(nlh, NULL, NULL);
  60}
  61
  62static void cmd_peer_rm_help(struct cmdl *cmdl)
  63{
  64        fprintf(stderr, "Usage: %s peer remove address ADDRESS\n",
  65                cmdl->argv[0]);
  66}
  67
  68static int cmd_peer_rm(struct nlmsghdr *nlh, const struct cmd *cmd,
  69                        struct cmdl *cmdl, void *data)
  70{
  71        const struct cmd cmds[] = {
  72                { "address",    cmd_peer_rm_addr,       cmd_peer_rm_help },
  73                { NULL }
  74        };
  75
  76        return run_cmd(nlh, cmd, cmds, cmdl, NULL);
  77}
  78
  79void cmd_peer_help(struct cmdl *cmdl)
  80{
  81        fprintf(stderr,
  82                "Usage: %s peer COMMAND [ARGS] ...\n\n"
  83                "COMMANDS\n"
  84                " remove                - Remove an offline peer node\n",
  85                cmdl->argv[0]);
  86}
  87
  88int cmd_peer(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl,
  89             void *data)
  90{
  91        const struct cmd cmds[] = {
  92                { "remove",     cmd_peer_rm,    cmd_peer_rm_help },
  93                { NULL }
  94        };
  95
  96        return run_cmd(nlh, cmd, cmds, cmdl, NULL);
  97}
  98