prog.c (ec2025095cf6acda3233a4301809596938b47da5) prog.c (a7d22ca2a483d6c69c0791954447464297315ffa)
1// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2/* Copyright (C) 2017-2018 Netronome Systems, Inc. */
3
4#define _GNU_SOURCE
5#include <errno.h>
6#include <fcntl.h>
7#include <stdarg.h>
8#include <stdio.h>

--- 68 unchanged lines hidden (view full) ---

77 }
78
79 if (json_output)
80 strftime(buf, size, "%s", &load_tm);
81 else
82 strftime(buf, size, "%FT%T%z", &load_tm);
83}
84
1// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2/* Copyright (C) 2017-2018 Netronome Systems, Inc. */
3
4#define _GNU_SOURCE
5#include <errno.h>
6#include <fcntl.h>
7#include <stdarg.h>
8#include <stdio.h>

--- 68 unchanged lines hidden (view full) ---

77 }
78
79 if (json_output)
80 strftime(buf, size, "%s", &load_tm);
81 else
82 strftime(buf, size, "%FT%T%z", &load_tm);
83}
84
85static int prog_fd_by_tag(unsigned char *tag, int **fds)
85static int prog_fd_by_nametag(void *nametag, int **fds, bool tag)
86{
87 unsigned int id = 0;
88 int fd, nb_fds = 0;
89 void *tmp;
90 int err;
91
92 while (true) {
93 struct bpf_prog_info info = {};

--- 17 unchanged lines hidden (view full) ---

111
112 err = bpf_obj_get_info_by_fd(fd, &info, &len);
113 if (err) {
114 p_err("can't get prog info (%u): %s",
115 id, strerror(errno));
116 goto err_close_fd;
117 }
118
86{
87 unsigned int id = 0;
88 int fd, nb_fds = 0;
89 void *tmp;
90 int err;
91
92 while (true) {
93 struct bpf_prog_info info = {};

--- 17 unchanged lines hidden (view full) ---

111
112 err = bpf_obj_get_info_by_fd(fd, &info, &len);
113 if (err) {
114 p_err("can't get prog info (%u): %s",
115 id, strerror(errno));
116 goto err_close_fd;
117 }
118
119 if (memcmp(tag, info.tag, BPF_TAG_SIZE)) {
119 if ((tag && memcmp(nametag, info.tag, BPF_TAG_SIZE)) ||
120 (!tag && strncmp(nametag, info.name, BPF_OBJ_NAME_LEN))) {
120 close(fd);
121 continue;
122 }
123
124 if (nb_fds > 0) {
125 tmp = realloc(*fds, (nb_fds + 1) * sizeof(int));
126 if (!tmp) {
127 p_err("failed to realloc");

--- 41 unchanged lines hidden (view full) ---

169 if (sscanf(**argv, BPF_TAG_FMT, tag, tag + 1, tag + 2,
170 tag + 3, tag + 4, tag + 5, tag + 6, tag + 7)
171 != BPF_TAG_SIZE) {
172 p_err("can't parse tag");
173 return -1;
174 }
175 NEXT_ARGP();
176
121 close(fd);
122 continue;
123 }
124
125 if (nb_fds > 0) {
126 tmp = realloc(*fds, (nb_fds + 1) * sizeof(int));
127 if (!tmp) {
128 p_err("failed to realloc");

--- 41 unchanged lines hidden (view full) ---

170 if (sscanf(**argv, BPF_TAG_FMT, tag, tag + 1, tag + 2,
171 tag + 3, tag + 4, tag + 5, tag + 6, tag + 7)
172 != BPF_TAG_SIZE) {
173 p_err("can't parse tag");
174 return -1;
175 }
176 NEXT_ARGP();
177
177 return prog_fd_by_tag(tag, fds);
178 return prog_fd_by_nametag(tag, fds, true);
179 } else if (is_prefix(**argv, "name")) {
180 char *name;
181
182 NEXT_ARGP();
183
184 name = **argv;
185 if (strlen(name) > BPF_OBJ_NAME_LEN - 1) {
186 p_err("can't parse name");
187 return -1;
188 }
189 NEXT_ARGP();
190
191 return prog_fd_by_nametag(name, fds, false);
178 } else if (is_prefix(**argv, "pinned")) {
179 char *path;
180
181 NEXT_ARGP();
182
183 path = **argv;
184 NEXT_ARGP();
185
186 (*fds)[0] = open_obj_pinned_any(path, BPF_OBJ_PROG);
187 if ((*fds)[0] < 0)
188 return -1;
189 return 1;
190 }
191
192 } else if (is_prefix(**argv, "pinned")) {
193 char *path;
194
195 NEXT_ARGP();
196
197 path = **argv;
198 NEXT_ARGP();
199
200 (*fds)[0] = open_obj_pinned_any(path, BPF_OBJ_PROG);
201 if ((*fds)[0] < 0)
202 return -1;
203 return 1;
204 }
205
192 p_err("expected 'id', 'tag' or 'pinned', got: '%s'?", **argv);
206 p_err("expected 'id', 'tag', 'name' or 'pinned', got: '%s'?", **argv);
193 return -1;
194}
195
196int prog_parse_fd(int *argc, char ***argv)
197{
198 int *fds = NULL;
199 int nb_fds, fd;
200

--- 1394 unchanged lines hidden ---
207 return -1;
208}
209
210int prog_parse_fd(int *argc, char ***argv)
211{
212 int *fds = NULL;
213 int nb_fds, fd;
214

--- 1394 unchanged lines hidden ---