aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvaylo Asenov <ivaylo.asenov@linaro.org>2017-06-14 13:06:14 +0100
committerIvaylo Asenov <Ivaylo.Asenov@linaro.org>2017-06-14 13:07:50 +0100
commit9bbae7b233dfa3b9894ac6fdc6a41062ba5917ed (patch)
tree86338ce0b584f97eb2806a6d2f82a61c28a60503
parent807c9cc4668d932d6d76ec8b28c2a2868108c757 (diff)
downloadiproute2-linaro-upstream-4.11.0.tar.gz
Changes needed for ability to compilelinaro-upstream-4.11.0
Change-Id: I08440426277fd605181556a349f4c80ecb27342d Signed-off-by: Ivaylo Asenov <ivaylo.asenov@linaro.org>
-rw-r--r--include/bpf_scm.h2
-rw-r--r--include/utils.h2
-rw-r--r--ip/Android.mk4
-rw-r--r--ip/glob.c243
-rw-r--r--ip/glob.h50
-rw-r--r--ip/ipmaddr.c2
-rw-r--r--ip/iptuntap.c2
-rw-r--r--lib/Android.mk3
-rw-r--r--lib/utils.c6
-rw-r--r--misc/ssfilter.y2
10 files changed, 308 insertions, 8 deletions
diff --git a/include/bpf_scm.h b/include/bpf_scm.h
index 35117d11..a771453c 100644
--- a/include/bpf_scm.h
+++ b/include/bpf_scm.h
@@ -32,7 +32,7 @@ struct bpf_map_set_msg {
};
static inline int *bpf_map_set_init(struct bpf_map_set_msg *msg,
- struct sockaddr_un *addr,
+ struct sockaddr_in *addr,
unsigned int addr_len)
{
const unsigned int cmsg_ctl_len = sizeof(int) * BPF_SCM_MAX_FDS;
diff --git a/include/utils.h b/include/utils.h
index 8c12e1e2..8708b1ca 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -11,6 +11,8 @@
#include "ll_map.h"
#include "rtm_map.h"
+#include <time.h>
+
extern int preferred_family;
extern int human_readable;
extern int use_iec;
diff --git a/ip/Android.mk b/ip/Android.mk
index 5c45bc76..21f9fc53 100644
--- a/ip/Android.mk
+++ b/ip/Android.mk
@@ -8,7 +8,9 @@ LOCAL_SRC_FILES := ip.c ipaddress.c ipaddrlabel.c iproute.c iprule.c ipnetns.c \
iplink_vlan.c link_veth.c link_gre.c iplink_can.c \
iplink_macvlan.c ipl2tp.c \
ipfou.c iptoken.c tcp_metrics.c ipnetconf.c \
- iproute_lwtunnel.c
+ iproute_lwtunnel.c ipila.c iplink_xdp.c iplink_dummy.c \
+ iplink_ifb.c iplink_nlmon.c iplink_team.c iplink_vcan.c \
+ iplink_xstats.c ipmacsec.c ipvrf.c iplink_vrf.c glob.c
LOCAL_MODULE := ip
diff --git a/ip/glob.c b/ip/glob.c
new file mode 100644
index 00000000..0dbe1c7d
--- /dev/null
+++ b/ip/glob.c
@@ -0,0 +1,243 @@
+#include <glob.h>
+#include <fnmatch.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <limits.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <stddef.h>
+//#include "libc.h"
+
+#include <unistd.h>
+#include <string.h>
+#include <pthread.h>
+
+struct match
+{
+ struct match *next;
+ char name[1];
+};
+
+static int is_literal(const char *p, int useesc)
+{
+ int bracket = 0;
+ for (; *p; p++) {
+ switch (*p) {
+ case '\\':
+ if (!useesc) break;
+ case '?':
+ case '*':
+ return 0;
+ case '[':
+ bracket = 1;
+ break;
+ case ']':
+ if (bracket) return 0;
+ break;
+ }
+ }
+ return 1;
+}
+
+static int append(struct match **tail, const char *name, size_t len, int mark)
+{
+ struct match *new = malloc(sizeof(struct match) + len + 1);
+ if (!new) return -1;
+ (*tail)->next = new;
+ new->next = NULL;
+ strcpy(new->name, name);
+ if (mark) strcat(new->name, "/");
+ *tail = new;
+ return 0;
+}
+
+static int match_in_dir(const char *d, const char *p, int flags, int (*errfunc)(const char *path, int err), struct match **tail)
+{
+ DIR *dir;
+ struct dirent de_buf, *de;
+ char pat[strlen(p)+1];
+ char *p2;
+ size_t l = strlen(d);
+ int literal;
+ int fnm_flags= ((flags & GLOB_NOESCAPE) ? FNM_NOESCAPE : 0)
+ | ((!(flags & GLOB_PERIOD)) ? FNM_PERIOD : 0);
+ int error;
+
+ if ((p2 = strchr(p, '/'))) {
+ strcpy(pat, p);
+ pat[p2-p] = 0;
+ for (; *p2 == '/'; p2++);
+ p = pat;
+ }
+ literal = is_literal(p, !(flags & GLOB_NOESCAPE));
+ if (*d == '/' && !*(d+1)) l = 0;
+
+ /* rely on opendir failing for nondirectory objects */
+ dir = opendir(*d ? d : ".");
+ error = errno;
+ if (!dir) {
+ /* this is not an error -- we let opendir call stat for us */
+ if (error == ENOTDIR) return 0;
+ if (error == EACCES && !*p) {
+ struct stat st;
+ if (!stat(d, &st) && S_ISDIR(st.st_mode)) {
+ if (append(tail, d, l, l))
+ return GLOB_NOSPACE;
+ return 0;
+ }
+ }
+ if (errfunc(d, error) || (flags & GLOB_ERR))
+ return GLOB_ABORTED;
+ return 0;
+ }
+ if (!*p) {
+ error = append(tail, d, l, l) ? GLOB_NOSPACE : 0;
+ closedir(dir);
+ return error;
+ }
+ while (!(error = readdir_r(dir, &de_buf, &de)) && de) {
+ char namebuf[l+de->d_reclen+2], *name = namebuf;
+ if (!literal && fnmatch(p, de->d_name, fnm_flags))
+ continue;
+ if (literal && strcmp(p, de->d_name))
+ continue;
+ if (p2 && de->d_type && !S_ISDIR(de->d_type<<12) && !S_ISLNK(de->d_type<<12))
+ continue;
+ if (*d) {
+ memcpy(name, d, l);
+ name[l] = '/';
+ strcpy(name+l+1, de->d_name);
+ } else {
+ name = de->d_name;
+ }
+ if (p2) {
+ if ((error = match_in_dir(name, p2, flags, errfunc, tail))) {
+ closedir(dir);
+ return error;
+ }
+ } else {
+ int mark = 0;
+ if (flags & GLOB_MARK) {
+ if (de->d_type && !S_ISLNK(de->d_type<<12))
+ mark = S_ISDIR(de->d_type<<12);
+ else {
+ struct stat st;
+ stat(name, &st);
+ mark = S_ISDIR(st.st_mode);
+ }
+ }
+ if (append(tail, name, l+de->d_reclen+1, mark)) {
+ closedir(dir);
+ return GLOB_NOSPACE;
+ }
+ }
+ }
+ closedir(dir);
+ if (error && (errfunc(d, error) || (flags & GLOB_ERR)))
+ return GLOB_ABORTED;
+ return 0;
+}
+
+static int ignore_err(const char *path, int err)
+{
+ return 0;
+}
+
+static void freelist(struct match *head)
+{
+ struct match *match, *next;
+ for (match=head->next; match; match=next) {
+ next = match->next;
+ free(match);
+ }
+}
+
+static int sort(const void *a, const void *b)
+{
+ return strcmp(*(const char **)a, *(const char **)b);
+}
+
+int glob(const char *restrict pat, int flags, int (*errfunc)(const char *path, int err), glob_t *restrict g)
+{
+ const char *p=pat, *d;
+ struct match head = { .next = NULL }, *tail = &head;
+ size_t cnt, i;
+ size_t offs = (flags & GLOB_DOOFFS) ? g->gl_offs : 0;
+ int error = 0;
+
+ if (*p == '/') {
+ for (; *p == '/'; p++);
+ d = "/";
+ } else {
+ d = "";
+ }
+
+ if (!errfunc) errfunc = ignore_err;
+
+ if (!(flags & GLOB_APPEND)) {
+ g->gl_offs = offs;
+ g->gl_pathc = 0;
+ g->gl_pathv = NULL;
+ }
+
+ if (strnlen(p, PATH_MAX+1) > PATH_MAX) return GLOB_NOSPACE;
+
+ if (*pat) error = match_in_dir(d, p, flags, errfunc, &tail);
+ if (error == GLOB_NOSPACE) {
+ freelist(&head);
+ return error;
+ }
+
+ for (cnt=0, tail=head.next; tail; tail=tail->next, cnt++);
+ if (!cnt) {
+ if (flags & GLOB_NOCHECK) {
+ tail = &head;
+ if (append(&tail, pat, strlen(pat), 0))
+ return GLOB_NOSPACE;
+ cnt++;
+ } else
+ return GLOB_NOMATCH;
+ }
+
+ if (flags & GLOB_APPEND) {
+ char **pathv = realloc(g->gl_pathv, (offs + g->gl_pathc + cnt + 1) * sizeof(char *));
+ if (!pathv) {
+ freelist(&head);
+ return GLOB_NOSPACE;
+ }
+ g->gl_pathv = pathv;
+ offs += g->gl_pathc;
+ } else {
+ g->gl_pathv = malloc((offs + cnt + 1) * sizeof(char *));
+ if (!g->gl_pathv) {
+ freelist(&head);
+ return GLOB_NOSPACE;
+ }
+ for (i=0; i<offs; i++)
+ g->gl_pathv[i] = NULL;
+ }
+ for (i=0, tail=head.next; i<cnt; tail=tail->next, i++)
+ g->gl_pathv[offs + i] = tail->name;
+ g->gl_pathv[offs + i] = NULL;
+ g->gl_pathc += cnt;
+
+ if (!(flags & GLOB_NOSORT))
+ qsort(g->gl_pathv+offs, cnt, sizeof(char *), sort);
+
+ return error;
+}
+
+void globfree(glob_t *g)
+{
+ size_t i;
+ for (i=0; i<g->gl_pathc; i++)
+ free(g->gl_pathv[g->gl_offs + i] - offsetof(struct match, name));
+ free(g->gl_pathv);
+ g->gl_pathc = 0;
+ g->gl_pathv = NULL;
+}
+
+//LFS64(glob);
+//LFS64(globfree);
+
diff --git a/ip/glob.h b/ip/glob.h
new file mode 100644
index 00000000..8b691932
--- /dev/null
+++ b/ip/glob.h
@@ -0,0 +1,50 @@
+#ifndef _GLOB_H
+#define _GLOB_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <features.h>
+
+#define __NEED_size_t
+
+//#include "alltypes.h"
+#include <stddef.h>
+
+typedef struct {
+ size_t gl_pathc;
+ char **gl_pathv;
+ size_t gl_offs;
+ int __dummy1;
+ void *__dummy2[5];
+} glob_t;
+
+int glob(const char *__restrict, int, int (*)(const char *, int), glob_t *__restrict);
+void globfree(glob_t *);
+
+#define GLOB_ERR 0x01
+#define GLOB_MARK 0x02
+#define GLOB_NOSORT 0x04
+#define GLOB_DOOFFS 0x08
+#define GLOB_NOCHECK 0x10
+#define GLOB_APPEND 0x20
+#define GLOB_NOESCAPE 0x40
+#define GLOB_PERIOD 0x80
+
+#define GLOB_NOSPACE 1
+#define GLOB_ABORTED 2
+#define GLOB_NOMATCH 3
+#define GLOB_NOSYS 4
+
+#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
+#define glob64 glob
+#define globfree64 globfree
+#define glob64_t glob_t
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/ip/ipmaddr.c b/ip/ipmaddr.c
index 4f726fdd..85a69e77 100644
--- a/ip/ipmaddr.c
+++ b/ip/ipmaddr.c
@@ -136,7 +136,7 @@ static void read_igmp(struct ma_info **result_p)
while (fgets(buf, sizeof(buf), fp)) {
struct ma_info *ma;
- size_t len;
+ size_t len = 0;
if (buf[0] != '\t') {
sscanf(buf, "%d%s", &m.index, m.name);
diff --git a/ip/iptuntap.c b/ip/iptuntap.c
index 451f7f0e..9715891a 100644
--- a/ip/iptuntap.c
+++ b/ip/iptuntap.c
@@ -25,7 +25,7 @@
#include <fcntl.h>
#include <dirent.h>
#include <errno.h>
-#include <glob.h>
+#include "glob.h"
#include "rt_names.h"
#include "utils.h"
diff --git a/lib/Android.mk b/lib/Android.mk
index 3fa5a5ee..c62fd363 100644
--- a/lib/Android.mk
+++ b/lib/Android.mk
@@ -3,7 +3,8 @@ LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := \
color.c utils.c rt_names.c ll_types.c ll_proto.c ll_addr.c inet_proto.c \
- mpls_pton.c namespace.c names.c libgenl.c libnetlink.c
+ mpls_pton.c namespace.c names.c libgenl.c libnetlink.c bpf.c exec.c fs.c \
+
LOCAL_MODULE := libiprouteutil
LOCAL_SYSTEM_SHARED_LIBRARIES := libc
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../include
diff --git a/lib/utils.c b/lib/utils.c
index 6d5642f4..3754f1ab 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -504,7 +504,7 @@ int get_addr_1(inet_prefix *addr, const char *name, int family)
addr->bitlen = -1;
return 0;
}
-
+#ifndef ANDROID
if (family == AF_DECnet) {
struct dn_naddr dna;
@@ -516,7 +516,7 @@ int get_addr_1(inet_prefix *addr, const char *name, int family)
addr->bitlen = -1;
return 0;
}
-
+#endif
if (family == AF_MPLS) {
int i;
@@ -775,6 +775,7 @@ const char *rt_addr_n2a_r(int af, int len,
case AF_INET:
case AF_INET6:
return inet_ntop(af, addr, buf, buflen);
+#ifndef ANDROID
case AF_MPLS:
return mpls_ntop(af, addr, buf, buflen);
case AF_IPX:
@@ -786,6 +787,7 @@ const char *rt_addr_n2a_r(int af, int len,
memcpy(dna.a_addr, addr, 2);
return dnet_ntop(af, &dna, buf, buflen);
}
+#endif
case AF_PACKET:
return ll_addr_n2a(addr, len, ARPHRD_VOID, buf, buflen);
default:
diff --git a/misc/ssfilter.y b/misc/ssfilter.y
index ba82b65f..0a4e98b8 100644
--- a/misc/ssfilter.y
+++ b/misc/ssfilter.y
@@ -4,7 +4,7 @@
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
-#include "ssfilter.h"
+#include <ssfilter.h>
typedef struct ssfilter * ssfilter_t;