static int compute_score(struct sock *sk, struct net *net,
                         __be32 saddr, __be16 sport,
-                        __be32 daddr, unsigned short hnum, int dif,
-                        bool exact_dif)
+                        __be32 daddr, unsigned short hnum,
+                        int dif, int sdif, bool exact_dif)
 {
        int score;
        struct inet_sock *inet;
        }
 
        if (sk->sk_bound_dev_if || exact_dif) {
-               if (sk->sk_bound_dev_if != dif)
+               bool dev_match = (sk->sk_bound_dev_if == dif ||
+                                 sk->sk_bound_dev_if == sdif);
+
+               if (exact_dif && !dev_match)
                        return -1;
-               score += 4;
+               if (sk->sk_bound_dev_if && dev_match)
+                       score += 4;
        }
+
        if (sk->sk_incoming_cpu == raw_smp_processor_id())
                score++;
        return score;
 
 /* called with rcu_read_lock() */
 static struct sock *udp4_lib_lookup2(struct net *net,
-               __be32 saddr, __be16 sport,
-               __be32 daddr, unsigned int hnum, int dif, bool exact_dif,
-               struct udp_hslot *hslot2,
-               struct sk_buff *skb)
+                                    __be32 saddr, __be16 sport,
+                                    __be32 daddr, unsigned int hnum,
+                                    int dif, int sdif, bool exact_dif,
+                                    struct udp_hslot *hslot2,
+                                    struct sk_buff *skb)
 {
        struct sock *sk, *result;
        int score, badness, matches = 0, reuseport = 0;
        badness = 0;
        udp_portaddr_for_each_entry_rcu(sk, &hslot2->head) {
                score = compute_score(sk, net, saddr, sport,
-                                     daddr, hnum, dif, exact_dif);
+                                     daddr, hnum, dif, sdif, exact_dif);
                if (score > badness) {
                        reuseport = sk->sk_reuseport;
                        if (reuseport) {
  * harder than this. -DaveM
  */
 struct sock *__udp4_lib_lookup(struct net *net, __be32 saddr,
-               __be16 sport, __be32 daddr, __be16 dport,
-               int dif, struct udp_table *udptable, struct sk_buff *skb)
+               __be16 sport, __be32 daddr, __be16 dport, int dif,
+               int sdif, struct udp_table *udptable, struct sk_buff *skb)
 {
        struct sock *sk, *result;
        unsigned short hnum = ntohs(dport);
                        goto begin;
 
                result = udp4_lib_lookup2(net, saddr, sport,
-                                         daddr, hnum, dif,
+                                         daddr, hnum, dif, sdif,
                                          exact_dif, hslot2, skb);
                if (!result) {
                        unsigned int old_slot2 = slot2;
                                goto begin;
 
                        result = udp4_lib_lookup2(net, saddr, sport,
-                                                 daddr, hnum, dif,
+                                                 daddr, hnum, dif, sdif,
                                                  exact_dif, hslot2, skb);
                }
                return result;
        badness = 0;
        sk_for_each_rcu(sk, &hslot->head) {
                score = compute_score(sk, net, saddr, sport,
-                                     daddr, hnum, dif, exact_dif);
+                                     daddr, hnum, dif, sdif, exact_dif);
                if (score > badness) {
                        reuseport = sk->sk_reuseport;
                        if (reuseport) {
 
        return __udp4_lib_lookup(dev_net(skb->dev), iph->saddr, sport,
                                 iph->daddr, dport, inet_iif(skb),
-                                udptable, skb);
+                                inet_sdif(skb), udptable, skb);
 }
 
 struct sock *udp4_lib_lookup_skb(struct sk_buff *skb,
        struct sock *sk;
 
        sk = __udp4_lib_lookup(net, saddr, sport, daddr, dport,
-                              dif, &udp_table, NULL);
+                              dif, 0, &udp_table, NULL);
        if (sk && !refcount_inc_not_zero(&sk->sk_refcnt))
                sk = NULL;
        return sk;
 static inline bool __udp_is_mcast_sock(struct net *net, struct sock *sk,
                                       __be16 loc_port, __be32 loc_addr,
                                       __be16 rmt_port, __be32 rmt_addr,
-                                      int dif, unsigned short hnum)
+                                      int dif, int sdif, unsigned short hnum)
 {
        struct inet_sock *inet = inet_sk(sk);
 
            (inet->inet_dport != rmt_port && inet->inet_dport) ||
            (inet->inet_rcv_saddr && inet->inet_rcv_saddr != loc_addr) ||
            ipv6_only_sock(sk) ||
-           (sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
+           (sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif &&
+            sk->sk_bound_dev_if != sdif))
                return false;
        if (!ip_mc_sf_allow(sk, loc_addr, rmt_addr, dif))
                return false;
        struct net *net = dev_net(skb->dev);
 
        sk = __udp4_lib_lookup(net, iph->daddr, uh->dest,
-                       iph->saddr, uh->source, skb->dev->ifindex, udptable,
-                       NULL);
+                              iph->saddr, uh->source, skb->dev->ifindex, 0,
+                              udptable, NULL);
        if (!sk) {
                __ICMP_INC_STATS(net, ICMP_MIB_INERRORS);
                return; /* No socket for error */
        unsigned int hash2 = 0, hash2_any = 0, use_hash2 = (hslot->count > 10);
        unsigned int offset = offsetof(typeof(*sk), sk_node);
        int dif = skb->dev->ifindex;
+       int sdif = inet_sdif(skb);
        struct hlist_node *node;
        struct sk_buff *nskb;
 
 
        sk_for_each_entry_offset_rcu(sk, node, &hslot->head, offset) {
                if (!__udp_is_mcast_sock(net, sk, uh->dest, daddr,
-                                        uh->source, saddr, dif, hnum))
+                                        uh->source, saddr, dif, sdif, hnum))
                        continue;
 
                if (!first) {
 static struct sock *__udp4_lib_mcast_demux_lookup(struct net *net,
                                                  __be16 loc_port, __be32 loc_addr,
                                                  __be16 rmt_port, __be32 rmt_addr,
-                                                 int dif)
+                                                 int dif, int sdif)
 {
        struct sock *sk, *result;
        unsigned short hnum = ntohs(loc_port);
        result = NULL;
        sk_for_each_rcu(sk, &hslot->head) {
                if (__udp_is_mcast_sock(net, sk, loc_port, loc_addr,
-                                       rmt_port, rmt_addr, dif, hnum)) {
+                                       rmt_port, rmt_addr, dif, sdif, hnum)) {
                        if (result)
                                return NULL;
                        result = sk;
        struct sock *sk = NULL;
        struct dst_entry *dst;
        int dif = skb->dev->ifindex;
+       int sdif = inet_sdif(skb);
        int ours;
 
        /* validate the packet */
                }
 
                sk = __udp4_lib_mcast_demux_lookup(net, uh->dest, iph->daddr,
-                                                  uh->source, iph->saddr, dif);
+                                                  uh->source, iph->saddr,
+                                                  dif, sdif);
        } else if (skb->pkt_type == PACKET_HOST) {
                sk = __udp4_lib_demux_lookup(net, uh->dest, iph->daddr,
                                             uh->source, iph->saddr, dif);
 
                sk = __udp4_lib_lookup(net,
                                req->id.idiag_src[0], req->id.idiag_sport,
                                req->id.idiag_dst[0], req->id.idiag_dport,
-                               req->id.idiag_if, tbl, NULL);
+                               req->id.idiag_if, 0, tbl, NULL);
 #if IS_ENABLED(CONFIG_IPV6)
        else if (req->sdiag_family == AF_INET6)
                sk = __udp6_lib_lookup(net,
                sk = __udp4_lib_lookup(net,
                                req->id.idiag_dst[0], req->id.idiag_dport,
                                req->id.idiag_src[0], req->id.idiag_sport,
-                               req->id.idiag_if, tbl, NULL);
+                               req->id.idiag_if, 0, tbl, NULL);
 #if IS_ENABLED(CONFIG_IPV6)
        else if (req->sdiag_family == AF_INET6) {
                if (ipv6_addr_v4mapped((struct in6_addr *)req->id.idiag_dst) &&
                        sk = __udp4_lib_lookup(net,
                                        req->id.idiag_dst[3], req->id.idiag_dport,
                                        req->id.idiag_src[3], req->id.idiag_sport,
-                                       req->id.idiag_if, tbl, NULL);
+                                       req->id.idiag_if, 0, tbl, NULL);
 
                else
                        sk = __udp6_lib_lookup(net,