Fix ng_ksocket(4) operation as a divert socket, which is pretty useful
and has been broken twice: - in the beginning of div_output() replace KASSERT with assignment, as it was in rev. 1.83. [1] [to be MFCed] - refactor changes introduced in rev. 1.100: do not prepend a new tag unconditionally. Before doing this check whether we have one. [2] A small note for all hacking in this area: when divert socket is not a real userland, but ng_ksocket(4), we receive _the same_ mbufs, that we transmitted to socket. These mbufs have rcvif, the tags we've put on them. And we should treat them correctly. Discussed with: mlaier [1] Silence from: green [2] Reviewed by: maxim Approved by: julian (mentor) MFC after: 1 week
This commit is contained in:
parent
8e10380a9f
commit
ea0bd57615
@ -277,21 +277,22 @@ div_output(struct socket *so, struct mbuf *m,
|
||||
struct divert_tag *dt;
|
||||
int error = 0;
|
||||
|
||||
KASSERT(m->m_pkthdr.rcvif == NULL, ("rcvif not null"));
|
||||
m->m_pkthdr.rcvif = NULL;
|
||||
|
||||
if (control)
|
||||
m_freem(control); /* XXX */
|
||||
|
||||
mtag = m_tag_get(PACKET_TAG_DIVERT,
|
||||
sizeof(struct divert_tag), M_NOWAIT);
|
||||
if (mtag == NULL) {
|
||||
error = ENOBUFS;
|
||||
goto cantsend;
|
||||
}
|
||||
dt = (struct divert_tag *)(mtag+1);
|
||||
dt->info = 0;
|
||||
dt->cookie = 0;
|
||||
m_tag_prepend(m, mtag);
|
||||
if ((mtag = m_tag_find(m, PACKET_TAG_DIVERT, NULL)) == NULL) {
|
||||
mtag = m_tag_get(PACKET_TAG_DIVERT, sizeof(struct divert_tag),
|
||||
M_NOWAIT | M_ZERO);
|
||||
if (mtag == NULL) {
|
||||
error = ENOBUFS;
|
||||
goto cantsend;
|
||||
}
|
||||
dt = (struct divert_tag *)(mtag+1);
|
||||
m_tag_prepend(m, mtag);
|
||||
} else
|
||||
dt = (struct divert_tag *)(mtag+1);
|
||||
|
||||
/* Loopback avoidance and state recovery */
|
||||
if (sin) {
|
||||
|
Loading…
Reference in New Issue
Block a user