-+ if (connection_sk) {
-+ connection_sk->sk_peercred.gid = connection_sk->sk_peercred.uid = ct->xid[dir];
-+ ct->xid[!dir]=connection_sk->sk_nid;
-+ if (connection_sk->sk_nid != 0)
-+ mark = connection_sk->sk_nid;
++
++ if (connection_sk /* Well, some kind of TCP socket */) {
++ if (connection_sk->sk_peercred.uid < 1) {
++ /* Normal case - the peercred on the socket is not set */
++ connection_sk->sk_peercred.gid = connection_sk->sk_peercred.uid = ct->xid[!dir];
++ }
++ else /* Exceptional case - the peercred was set using SET_PEERCRED. Somebody wants us
++ to mark packets with some arbitrary value.*/
++ mark=connection_sk->sk_peercred.uid;
++
++ /* Has this connection already been tagged? */
++ if (ct->xid[dir] < 1) {
++ /* No - let's tag it */
++ ct->xid[dir]=connection_sk->sk_nid;
++ }
++
++ if (mark==-1 && (connection_sk->sk_nid != 0))
++ mark = ct->xid[dir];
++
++