iproute2/ip/iplink_rmnet.c
<<
>>
Prefs
   1/* SPDX-License-Identifier: GPL-2.0 */
   2/*
   3 * iplink_rmnet.c       RMNET device support
   4 *
   5 * Authors:     Daniele Palmas <dnlplm@gmail.com>
   6 */
   7
   8#include <stdio.h>
   9#include <stdlib.h>
  10#include <string.h>
  11
  12#include "utils.h"
  13#include "ip_common.h"
  14
  15static void print_explain(FILE *f)
  16{
  17        fprintf(f,
  18                "Usage: ... rmnet mux_id MUXID\n"
  19                "\n"
  20                "MUXID := 1-254\n"
  21        );
  22}
  23
  24static void explain(void)
  25{
  26        print_explain(stderr);
  27}
  28
  29static int rmnet_parse_opt(struct link_util *lu, int argc, char **argv,
  30                           struct nlmsghdr *n)
  31{
  32        __u16 mux_id;
  33
  34        while (argc > 0) {
  35                if (matches(*argv, "mux_id") == 0) {
  36                        NEXT_ARG();
  37                        if (get_u16(&mux_id, *argv, 0))
  38                                invarg("mux_id is invalid", *argv);
  39                        addattr16(n, 1024, IFLA_RMNET_MUX_ID, mux_id);
  40                } else if (matches(*argv, "help") == 0) {
  41                        explain();
  42                        return -1;
  43                } else {
  44                        fprintf(stderr, "rmnet: unknown command \"%s\"?\n", *argv);
  45                        explain();
  46                        return -1;
  47                }
  48                argc--, argv++;
  49        }
  50
  51        return 0;
  52}
  53
  54static void rmnet_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
  55{
  56        if (!tb)
  57                return;
  58
  59        if (!tb[IFLA_RMNET_MUX_ID] ||
  60            RTA_PAYLOAD(tb[IFLA_RMNET_MUX_ID]) < sizeof(__u16))
  61                return;
  62
  63        print_uint(PRINT_ANY,
  64                   "mux_id",
  65                   "mux_id %u ",
  66                   rta_getattr_u16(tb[IFLA_RMNET_MUX_ID]));
  67}
  68
  69static void rmnet_print_help(struct link_util *lu, int argc, char **argv,
  70                             FILE *f)
  71{
  72        print_explain(f);
  73}
  74
  75struct link_util rmnet_link_util = {
  76        .id             = "rmnet",
  77        .maxattr        = IFLA_RMNET_MAX,
  78        .parse_opt      = rmnet_parse_opt,
  79        .print_opt      = rmnet_print_opt,
  80        .print_help     = rmnet_print_help,
  81};
  82