Lines 1-125
Link Here
|
1 |
Index: src/iface.c |
1 |
--- src/iface.c.orig 2016-01-06 15:42:06 UTC |
2 |
=================================================================== |
2 |
+++ src/iface.c |
3 |
RCS file: /cvsroot/mpd/mpd/src/iface.c,v |
3 |
@@ -161,7 +161,7 @@ |
4 |
retrieving revision 1.228 |
4 |
IfaceSetCommand, NULL, 2, (void *) SET_ADDRS }, |
5 |
retrieving revision 1.230 |
5 |
{ "route {dest}[/{width}]", "Add IP route", |
6 |
diff -u -p -r1.228 -r1.230 |
6 |
IfaceSetCommand, NULL, 2, (void *) SET_ROUTE }, |
7 |
--- src/iface.c 17 May 2017 08:47:53 -0000 1.228 |
7 |
- { "mtu {size}", "Set max allowed interface MTU", |
8 |
+++ src/iface.c 1 Jul 2017 21:32:07 -0000 1.230 |
8 |
+ { "mtu {size} [override]", "Set max allowed or override interface MTU", |
9 |
@@ -141,6 +141,7 @@ |
9 |
IfaceSetCommand, NULL, 2, (void *) SET_MTU }, |
10 |
static int IfaceAllocACL (struct acl_pool ***ap, int start, char * ifname, int number); |
10 |
{ "name [{name}]", "Set interface name", |
11 |
static int IfaceFindACL (struct acl_pool *ap, char * ifname, int number); |
11 |
IfaceSetCommand, NULL, 2, (void *) SET_NAME }, |
12 |
static char * IfaceParseACL (char * src, IfaceState iface); |
12 |
@@ -288,6 +288,7 @@ IfaceInit(Bund b) |
13 |
+ static char * IfaceFixAclForDelete(char *r, char *buf, size_t len); |
13 |
/* Default configuration */ |
|
|
14 |
iface->mtu = NG_IFACE_MTU_DEFAULT; |
15 |
iface->max_mtu = NG_IFACE_MTU_DEFAULT; |
16 |
+ iface->mtu_override = 0; |
17 |
#ifdef SIOCSIFDESCR |
18 |
iface->ifdescr = NULL; |
19 |
iface->conf.ifdescr = NULL; |
20 |
@@ -1549,15 +1550,30 @@ IfaceSetCommand(Context ctx, int ac, char *av[], void |
21 |
case SET_MTU: |
22 |
{ |
23 |
int max_mtu; |
24 |
+ int override; |
25 |
|
26 |
/* Check */ |
27 |
- if (ac != 1) |
28 |
+ if (ac < 1 || ac > 2) |
29 |
return(-1); |
30 |
|
31 |
max_mtu = atoi(av[0]); |
32 |
+ override = 0; |
33 |
+ |
34 |
+ if (ac == 2 && av[1][0]) { |
35 |
+ if (strcmp(av[1], "override") == 0) |
36 |
+ override = 1; |
37 |
+ else |
38 |
+ Error("Invalid keyword %s", av[1]); |
39 |
+ } |
40 |
+ |
41 |
if (max_mtu < IFACE_MIN_MTU || max_mtu > IFACE_MAX_MTU) |
42 |
- Error("Invalid interface mtu %d", max_mtu); |
43 |
- iface->max_mtu = max_mtu; |
44 |
+ if (!override || max_mtu != 0) |
45 |
+ Error("Invalid interface mtu %d", max_mtu); |
46 |
+ |
47 |
+ if (max_mtu != 0) |
48 |
+ iface->max_mtu = max_mtu; |
49 |
+ if (override) |
50 |
+ iface->mtu_override = max_mtu; |
51 |
} |
52 |
break; |
53 |
|
54 |
@@ -1686,6 +1702,7 @@ IfaceStat(Context ctx, int ac, char *av[], void *arg) |
55 |
Printf("\tGroup : %s\r\n", iface->conf.ifgroup); |
14 |
#endif |
56 |
#endif |
|
|
57 |
Printf("\tMaximum MTU : %d bytes\r\n", iface->max_mtu); |
58 |
+ Printf("\tMTU override : %d bytes\r\n", iface->mtu_override); |
59 |
Printf("\tIdle timeout : %d seconds\r\n", iface->idle_timeout); |
60 |
Printf("\tSession timeout : %d seconds\r\n", iface->session_timeout); |
61 |
if (!u_rangeempty(&iface->conf.self_addr)) { |
62 |
@@ -1816,14 +1833,18 @@ IfaceSetMTU(Bund b, int mtu) |
63 |
return; |
64 |
} |
15 |
|
65 |
|
16 |
static int IfaceSetName(Bund b, const char * ifname); |
66 |
- if ((b->params.mtu > 0) && (mtu > b->params.mtu)) { |
17 |
@@ -602,18 +603,18 @@ IfaceUp(Bund b, int ready) |
67 |
+ if (!iface->mtu_override && (b->params.mtu > 0) && (mtu > b->params.mtu)) { |
18 |
while (acls != NULL) { |
68 |
mtu = b->params.mtu; |
19 |
/* allow both %aX and `peer_addr` macros */ |
69 |
Log(LG_IFACE2, ("[%s] IFACE: forcing MTU of auth backend: %d bytes", |
20 |
buf = IfaceParseACL(acls->rule, iface); |
70 |
b->name, mtu)); |
21 |
- strcpy(acls->rule, buf); |
|
|
22 |
+ acl = Mdup2(MB_IPFW, acls, sizeof(struct acl), sizeof(struct acl) + strlen(buf)); |
23 |
+ strcpy(acl->rule, buf); |
24 |
Freee(buf); |
25 |
- acl = Mdup(MB_IPFW, acls, sizeof(struct acl) + strlen(acls->rule)); |
26 |
acl->next = iface->tables; |
27 |
iface->tables = acl; |
28 |
- if (strncmp(acls->rule, "peer_addr", 9) == 0) { |
29 |
+ if (strncmp(acl->rule, "peer_addr", 9) == 0) { |
30 |
char hisaddr[20]; |
31 |
ExecCmd(LG_IFACE2, b->name, "%s table %d add %s", |
32 |
- PATH_IPFW, acls->real_number, |
33 |
+ PATH_IPFW, acl->real_number, |
34 |
u_addrtoa(&iface->peer_addr, hisaddr, sizeof(hisaddr))); |
35 |
} else { |
36 |
- ExecCmd(LG_IFACE2, b->name, "%s table %d add %s", PATH_IPFW, acls->real_number, acls->rule); |
37 |
+ ExecCmd(LG_IFACE2, b->name, "%s table %d add %s", PATH_IPFW, acl->real_number, acl->rule); |
38 |
} |
71 |
} |
39 |
acls = acls->next; |
72 |
|
40 |
}; |
73 |
- /* Limit MTU to configured maximum */ |
41 |
@@ -697,8 +698,10 @@ IfaceDown(Bund b) |
74 |
- if (mtu > iface->max_mtu) |
42 |
PATH_IPFW, acl->real_number, |
75 |
+ /* Limit MTU to configured maximum/override */ |
43 |
u_addrtoa(&iface->peer_addr, hisaddr, sizeof(hisaddr))); |
76 |
+ if (iface->mtu_override) { |
44 |
} else { |
77 |
+ mtu = iface->mtu_override; |
45 |
+ char buf[ACL_LEN]; |
78 |
+ Log(LG_IFACE2, ("[%s] IFACE: forcing MTU override: %d bytes", |
46 |
ExecCmd(LG_IFACE2, b->name, "%s table %d delete %s", |
79 |
+ b->name, mtu)); |
47 |
- PATH_IPFW, acl->real_number, acl->rule); |
80 |
+ } else if (mtu > iface->max_mtu) |
48 |
+ PATH_IPFW, acl->real_number, |
81 |
mtu = iface->max_mtu; |
49 |
+ IfaceFixAclForDelete(acl->rule, buf, sizeof(buf))); |
82 |
|
50 |
} |
83 |
/* Set MTU on interface */ |
51 |
aclnext = acl->next; |
84 |
@@ -3003,6 +3024,9 @@ IfaceSetupMSS(Bund b, uint16_t maxMSS) |
52 |
Freee(acl); |
85 |
/* Send configure message. */ |
53 |
@@ -946,6 +949,60 @@ IfaceParseACL (char * src, IfaceState if |
86 |
memset(&tcpmsscfg, 0, sizeof(tcpmsscfg)); |
54 |
Freee(buf1); |
87 |
tcpmsscfg.maxMSS = maxMSS; |
55 |
return(buf); |
|
|
56 |
} |
57 |
+ |
88 |
+ |
58 |
+/* |
89 |
+ Log(LG_IFACE2, ("[%s] IFACE: Configuring ng_tcpmss %s %u", |
59 |
+ * IfaceFixAclForDelete() |
90 |
+ b->name, path, (unsigned)tcpmsscfg.maxMSS)); |
60 |
+ * |
|
|
61 |
+ * Removes values from ipfw 'table-key value [...]' expression r, if any. |
62 |
+ * Returns buf pointer for modified expression or original r pointer |
63 |
+ * if no modifications were performed when no values were found or |
64 |
+ * buf found too short. |
65 |
+ * |
66 |
+ * len is size of buf. Strings are zero-terminated. |
67 |
+ * r and buf must point to non-overlapping memory areas. |
68 |
+ */ |
69 |
+ |
70 |
+static char* |
71 |
+IfaceFixAclForDelete(char *r, char *buf, size_t len) |
72 |
+{ |
73 |
+ static const char sep[] = " \t"; |
74 |
+ char *limit, *s; |
75 |
+ int i, state = 0; |
76 |
+ |
77 |
+/* |
78 |
+ * Possible state values: |
79 |
+ * |
80 |
+ * -1: skip value (otherwise copy); |
81 |
+ * 0: first iteration, do copy; |
82 |
+ * 1: not first iteration, do copy. |
83 |
+*/ |
84 |
+ |
85 |
+ s = buf; |
86 |
+ limit = buf + len; |
87 |
+ |
88 |
+ for (r += strspn(r, sep); /* Skip leading spaces. */ |
89 |
+ *r; /* Check for end of string. */ |
90 |
+ r += i, r += strspn(r, sep)) /* Advance and skip spaces again. */ |
91 |
+ { |
92 |
+ i = strcspn(r, sep); /* Find separator or end of string. */ |
93 |
+ if (state == 0 && r[i] == '\0') /* No separators in the rule? */ |
94 |
+ return r; |
95 |
+ if (state < 0) { /* Skip value. */ |
96 |
+ state = 1; |
97 |
+ continue; |
98 |
+ } |
99 |
+ if (limit - s < i + 1 + state) /* Check space. */ |
100 |
+ return r; |
101 |
+ if (state != 0) /* Insert separator. */ |
102 |
+ *s++ = ' '; |
103 |
+ memcpy(s, r, i); /* Copy IP address from the rule. */ |
104 |
+ s += i; |
105 |
+ state = -1; |
106 |
+ } |
107 |
+ *s = '\0'; |
108 |
+ |
109 |
+ return buf; |
110 |
+} |
111 |
#endif /* USE_IPFW */ |
112 |
|
91 |
|
113 |
/* |
92 |
snprintf(tcpmsscfg.inHook, sizeof(tcpmsscfg.inHook), "in"); |
114 |
Index: src/mbuf.c |
93 |
snprintf(tcpmsscfg.outHook, sizeof(tcpmsscfg.outHook), "out"); |
115 |
=================================================================== |
94 |
--- src/mbuf.c.orig 2016-01-06 15:42:06 UTC |
116 |
RCS file: /cvsroot/mpd/mpd/src/mbuf.c,v |
95 |
+++ src/mbuf.c |
117 |
retrieving revision 1.30 |
96 |
@@ -55,6 +55,20 @@ Mdup(const char *type, const void *src, size_t size) |
118 |
retrieving revision 1.31 |
|
|
119 |
diff -u -p -r1.30 -r1.31 |
120 |
--- src/mbuf.c 14 Jun 2011 10:40:19 -0000 1.30 |
121 |
+++ src/mbuf.c 29 Jun 2017 08:21:35 -0000 1.31 |
122 |
@@ -55,6 +55,20 @@ Mdup(const char *type, const void *src, |
123 |
} |
97 |
} |
124 |
|
98 |
|
125 |
void * |
99 |
void * |
Lines 140-153
Link Here
|
140 |
Mstrdup(const char *type, const void *src) |
114 |
Mstrdup(const char *type, const void *src) |
141 |
{ |
115 |
{ |
142 |
return (Mdup(type, src, strlen(src) + 1)); |
116 |
return (Mdup(type, src, strlen(src) + 1)); |
143 |
Index: src/mbuf.h |
117 |
--- src/mbuf.h.orig 2016-01-06 15:42:06 UTC |
144 |
=================================================================== |
118 |
+++ src/mbuf.h |
145 |
RCS file: /cvsroot/mpd/mpd/src/mbuf.h,v |
|
|
146 |
retrieving revision 1.25 |
147 |
retrieving revision 1.26 |
148 |
diff -u -p -r1.25 -r1.26 |
149 |
--- src/mbuf.h 7 Oct 2013 11:52:35 -0000 1.25 |
150 |
+++ src/mbuf.h 29 Jun 2017 08:21:35 -0000 1.26 |
151 |
@@ -73,6 +73,7 @@ |
119 |
@@ -73,6 +73,7 @@ |
152 |
|
120 |
|
153 |
extern void *Malloc(const char *type, size_t size) __malloc_like; |
121 |
extern void *Malloc(const char *type, size_t size) __malloc_like; |